-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
K8SPG-375: Support installing custom extensions
- Loading branch information
Showing
28 changed files
with
43,728 additions
and
25,054 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,341 changes: 1,341 additions & 0 deletions
1,341
build/crd/crunchy/generated/postgres-operator.crunchydata.com_postgresclusters.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
1,785 changes: 1,608 additions & 177 deletions
1,785
build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM golang:1.20 AS go_builder | ||
WORKDIR /go/src/github.com/percona/percona-postgresql-operator | ||
|
||
COPY . . | ||
RUN go mod download | ||
|
||
ARG GIT_COMMIT | ||
ARG GIT_BRANCH | ||
ARG GO_LDFLAGS | ||
ARG GOOS=linux | ||
ARG GOARCH=amd64 | ||
ARG CGO_ENABLED=0 | ||
|
||
RUN mkdir -p build/_output/bin \ | ||
&& CGO_ENABLED=$CGO_ENABLED GOOS=$GOOS GOARCH=$GOARCH GO_LDFLAGS=$GO_LDFLAGS \ | ||
go build -ldflags "-w -s -X main.GitCommit=$GIT_COMMIT -X main.GitBranch=$GIT_BRANCH" \ | ||
-o build/_output/bin/extension-installer \ | ||
./cmd/extension-installer \ | ||
&& cp -r build/_output/bin/extension-installer /usr/local/bin/extension-installer | ||
|
||
|
||
RUN ./bin/license_aggregator.sh ./cmd/...; \ | ||
cp -r ./licenses /licenses | ||
|
||
FROM registry.access.redhat.com/ubi9/ubi-minimal AS ubi9 | ||
|
||
LABEL name="Percona Postgres Operator Custom Extension Installer" \ | ||
vendor="Percona" \ | ||
summary="Percona Postgres Operator performs Postgres database creation, adjustment and maintenance inside Kubernetes cluster" \ | ||
description="Percona Postgres Operator simplifies and automates all essential actions for stable and continuous database operation during the whole database lifecycle" \ | ||
maintainer="Percona Development <[email protected]>" | ||
|
||
RUN microdnf update -y && microdnf clean all -y | ||
|
||
COPY licenses /licenses | ||
|
||
COPY --from=go_builder /usr/local/bin/extension-installer /usr/local/bin | ||
COPY --from=go_builder /licenses /licenses | ||
|
||
USER 26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"io" | ||
"log" | ||
"os" | ||
"path" | ||
|
||
"github.com/percona/percona-postgresql-operator/percona/extensions" | ||
) | ||
|
||
func main() { | ||
var storageType, region, bucket, key string | ||
var install, uninstall bool | ||
|
||
flag.StringVar(&storageType, "type", "", "Storage type") | ||
flag.StringVar(®ion, "region", "", "Storage region") | ||
flag.StringVar(&bucket, "bucket", "", "Storage bucket") | ||
flag.StringVar(&key, "key", "", "Extension archive key") | ||
|
||
flag.BoolVar(&install, "install", false, "Install extension") | ||
flag.BoolVar(&uninstall, "uninstall", false, "Uninstall extension") | ||
flag.Parse() | ||
|
||
if (install && uninstall) || (!install && !uninstall) { | ||
log.Fatalf("ERROR: set either -install or -uninstall") | ||
} | ||
|
||
log.Printf("starting extension installer for %s/%s (%s) in %s", bucket, key, storageType, region) | ||
|
||
storage := initStorage(extensions.StorageType(storageType), bucket, region) | ||
|
||
object, err := storage.Get(key) | ||
if err != nil { | ||
log.Fatalf("ERROR: failed to get object: %v", err) | ||
} | ||
|
||
archivePath := path.Join("/tmp", key) | ||
|
||
// /tmp is not a good place due to its size limitation. | ||
dst, err := os.Create(archivePath) | ||
if err != nil { | ||
log.Fatalf("ERROR: failed to create file: %v", err) | ||
} | ||
defer dst.Close() | ||
|
||
written, err := io.Copy(dst, object) | ||
if err != nil { | ||
log.Fatalf("ERROR: failed to copy object: %v", err) | ||
} | ||
|
||
log.Printf("copied %d bytes to %s", written, dst.Name()) | ||
|
||
switch { | ||
case install: | ||
log.Printf("installing extension %s", archivePath) | ||
if err := extensions.Install(archivePath); err != nil { | ||
log.Fatalf("ERROR: failed to install extension: %v", err) | ||
} | ||
case uninstall: | ||
log.Printf("uninstalling extension %s", archivePath) | ||
if err := extensions.Uninstall(archivePath); err != nil { | ||
log.Fatalf("ERROR: failed to uninstall extension: %v", err) | ||
} | ||
} | ||
} | ||
|
||
func initStorage(storageType extensions.StorageType, bucket, region string) extensions.ObjectGetter { | ||
switch storageType { | ||
case extensions.StorageTypeS3: | ||
return extensions.NewS3(region, bucket) | ||
default: | ||
log.Fatalf("unknown storage type: %s", os.Getenv("STORAGE_TYPE")) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.