From ee6d06de3ed807759b8040bbd39d22f103fb658e Mon Sep 17 00:00:00 2001 From: "Jonathan S. Katz" Date: Wed, 12 Aug 2020 12:21:45 -0400 Subject: [PATCH] Update pgo-osb to PostgreSQL Operator 4.4.0 This brings the PGO OSB up-to-date with 4.4.0, particulary the API. Future work should use the modern method of interfacing with the Operator, though that can be handled in a late commit. Issue: #32 --- README.md | 8 ++-- centos7/Dockerfile.pgo-osb.centos7 | 4 +- config/pgoconfig.go | 2 +- deploy/deploy_notls.yaml | 2 +- deploy/deployment.yaml | 2 +- go.mod | 3 +- go.sum | 6 +++ pgo-osb.go | 32 +++++++++++++--- pkg/broker/pgo.go | 61 +++++++++++++++++++----------- 9 files changed, 83 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index a89dfd2..5ec9bd3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

-Latest Release: v4.2.1, 2020-01-31 +Latest Release: v4.4.0, 2020-08-12 ## General @@ -40,8 +40,8 @@ schedule and version number for the the Therefore, to ensure compatibility between **pgo-osb** and the PostgreSQL Operator, please ensure the version number for **pgo-osb** matches the version number of the PostgreSQL Operator deployed in your environment. For -instance, if you are using **pgo-osb** v4.2.1, please ensure the Crunchy -PostgreSQL Operator v4.2.1 is also deployed in your environment. +instance, if you are using **pgo-osb** v4.4.0, please ensure the Crunchy +PostgreSQL Operator v4.4.0 is also deployed in your environment. ## Prerequisites @@ -171,7 +171,7 @@ export OSB_NAMESPACE=demo export OSB_CMD=kubectl export OSB_ROOT=$GOPATH/src/github.com/crunchydata/pgo-osb export OSB_BASEOS=centos7 -export OSB_VERSION=4.2.1 +export OSB_VERSION=4.4.0 export OSB_IMAGE_TAG=$OSB_BASEOS-$OSB_VERSION export OSB_IMAGE_PREFIX=crunchydata ``` diff --git a/centos7/Dockerfile.pgo-osb.centos7 b/centos7/Dockerfile.pgo-osb.centos7 index 54c6060..ffb9417 100644 --- a/centos7/Dockerfile.pgo-osb.centos7 +++ b/centos7/Dockerfile.pgo-osb.centos7 @@ -1,8 +1,8 @@ FROM centos:7 LABEL Vendor="Crunchy Data Solutions" \ - Version="4.2.1" \ - Release="4.2.1" \ + Version="4.4.0" \ + Release="4.4.0" \ summary="Crunchy Data pgo-osb open service broker " \ description="Crunchy Data PostgreSQL Operator - pgo-osb " diff --git a/config/pgoconfig.go b/config/pgoconfig.go index b1abe1f..1d3313a 100644 --- a/config/pgoconfig.go +++ b/config/pgoconfig.go @@ -20,7 +20,7 @@ import ( "io/ioutil" "strconv" - crv1 "github.com/crunchydata/pgo-osb/apis/cr/v1" + crv1 "github.com/crunchydata/pgo-osb/v4/apis/cr/v1" log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) diff --git a/deploy/deploy_notls.yaml b/deploy/deploy_notls.yaml index 45652e0..51b3864 100644 --- a/deploy/deploy_notls.yaml +++ b/deploy/deploy_notls.yaml @@ -38,7 +38,7 @@ spec: - --PGO_APISERVER_URL - "https://postgres-operator:8443" - --PGO_APISERVER_VERSION - - "4.2.1" + - "4.4.0" - --insecure - "true" - --logtostderr diff --git a/deploy/deployment.yaml b/deploy/deployment.yaml index e913ef7..7d7469d 100644 --- a/deploy/deployment.yaml +++ b/deploy/deployment.yaml @@ -38,7 +38,7 @@ spec: - --PGO_APISERVER_URL - "https://postgres-operator:8443" - --PGO_APISERVER_VERSION - - "4.2.1" + - "4.4.0" - --logtostderr - --tls-cert-file - "/var/run/pgo-osb/server.crt" diff --git a/go.mod b/go.mod index bc8e893..948f76a 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/PuerkitoBio/purell v1.1.1 github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 github.com/beorn7/perks v1.0.1 - github.com/crunchydata/postgres-operator v4.2.3+incompatible + github.com/crunchydata/postgres-operator v4.4.0+incompatible github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c github.com/emicklei/go-restful v2.10.0+incompatible github.com/evanphx/json-patch v4.5.0+incompatible @@ -47,6 +47,7 @@ require ( github.com/shawn-hurley/osb-broker-k8s-lib v0.0.0-20180430125558-bed19ac36ffe github.com/sirupsen/logrus v1.4.2 github.com/spf13/pflag v1.0.5 + github.com/xdg/stringprep v1.0.0 // indirect golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc golang.org/x/net v0.0.0-20191003171128-d98b1b443823 golang.org/x/sys v0.0.0-20191007092633-5f54ce542709 diff --git a/go.sum b/go.sum index 4f7a668..831d6a4 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,11 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/crunchydata/postgres-operator v1.3.2 h1:hTPKWR3Gw9VFpQ+g5L1TLdv4kSQ5pVBjFpHYHgRZt5I= github.com/crunchydata/postgres-operator v4.2.3+incompatible h1:0uPiAHt0Qv+SfL/OSS1DiHd0/M7d3HvqmPqq5o7dJ3I= github.com/crunchydata/postgres-operator v4.2.3+incompatible/go.mod h1:oFjQzSNSrG0cUtqahIQDPO32bqCbg3hpwOMVJofNSyM= +github.com/crunchydata/postgres-operator v4.4.0+incompatible h1:CEx3g6zAdo7cfSrYnUvgHmeJ0/ExTyq1RbhxuwhJE30= +github.com/crunchydata/postgres-operator v4.4.0+incompatible/go.mod h1:oFjQzSNSrG0cUtqahIQDPO32bqCbg3hpwOMVJofNSyM= github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -157,6 +160,8 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0= +github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -210,4 +215,5 @@ k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUc k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d h1:Xpe6sK+RY4ZgCTyZ3y273UmFmURhjtoJiwOMbQsXitY= k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/pgo-osb.go b/pgo-osb.go index b8732dc..48a3470 100644 --- a/pgo-osb.go +++ b/pgo-osb.go @@ -25,16 +25,17 @@ import ( "strconv" "syscall" - "github.com/crunchydata/pgo-osb/pkg/osb-bridge" - "github.com/crunchydata/postgres-operator/config" - "github.com/crunchydata/postgres-operator/util" + bridge "github.com/crunchydata/pgo-osb/pkg/osb-bridge" + crv1 "github.com/crunchydata/postgres-operator/pkg/apis/crunchydata.com/v1" "github.com/gofrs/uuid" "github.com/pmorie/osb-broker-lib/pkg/metrics" "github.com/pmorie/osb-broker-lib/pkg/rest" "github.com/pmorie/osb-broker-lib/pkg/server" prom "github.com/prometheus/client_golang/prometheus" "github.com/shawn-hurley/osb-broker-k8s-lib/middleware" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" clientset "k8s.io/client-go/kubernetes" clientrest "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -69,7 +70,6 @@ func main() { flag.Parse() log.SetOutput(os.Stdout) - log.Println(config.LABEL_PG_CLUSTER) if options.PGO_OSB_GUID == "" { u, err := uuid.NewV4() @@ -206,7 +206,7 @@ func getRestClient(kubeConfigPath string) (*clientrest.RESTClient, error) { return nil, err } - restClient, _, err := util.NewClient(kubeConfig) + restClient, _, err := newClient(kubeConfig) if err != nil { return nil, err } @@ -214,6 +214,28 @@ func getRestClient(kubeConfigPath string) (*clientrest.RESTClient, error) { return restClient, nil } +// newClient gets a REST connection to Kubernetes. This is imported from an +// older version of the Operator and likely just needs to be redone +func newClient(cfg *clientrest.Config) (*clientrest.RESTClient, *runtime.Scheme, error) { + scheme := runtime.NewScheme() + if err := crv1.AddToScheme(scheme); err != nil { + return nil, nil, err + } + + config := *cfg + config.GroupVersion = &crv1.SchemeGroupVersion + config.APIPath = "/apis" + config.ContentType = runtime.ContentTypeJSON + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(scheme)} + + client, err := clientrest.RESTClientFor(&config) + if err != nil { + return nil, nil, err + } + + return client, scheme, nil +} + func cancelOnInterrupt(ctx context.Context, f context.CancelFunc) { term := make(chan os.Signal) signal.Notify(term, os.Interrupt, syscall.SIGTERM) diff --git a/pkg/broker/pgo.go b/pkg/broker/pgo.go index c995d8b..cb5f0e2 100644 --- a/pkg/broker/pgo.go +++ b/pkg/broker/pgo.go @@ -16,7 +16,6 @@ package broker */ import ( - "strconv" "crypto/tls" "crypto/x509" "errors" @@ -25,13 +24,13 @@ import ( "log" "net/http" "os" + "strconv" "strings" "sync" - crv1 "github.com/crunchydata/postgres-operator/apis/cr/v1" - msgs "github.com/crunchydata/postgres-operator/apiservermsgs" - "github.com/crunchydata/postgres-operator/kubeapi" api "github.com/crunchydata/postgres-operator/pgo/api" + crv1 "github.com/crunchydata/postgres-operator/pkg/apis/crunchydata.com/v1" + msgs "github.com/crunchydata/postgres-operator/pkg/apiservermsgs" "k8s.io/client-go/rest" ) @@ -95,8 +94,12 @@ func (po *PGOperator) findInstanceNamespace(instID string) (string, error) { selector := po.instLabel(instID) log.Print("find cluster " + selector) - clusterList := crv1.PgclusterList{} - err := kubeapi.GetpgclustersBySelector(po.kubeClient, &clusterList, selector, "") + clusterList := &crv1.PgclusterList{} + err := po.kubeClient.Get(). + Resource(crv1.PgclusterResourcePlural). + Param("labelSelector", selector). + Do(). + Into(clusterList) if err != nil { return "", err } @@ -176,30 +179,48 @@ func (po *PGOperator) createRequestByPlan(planID string, req *msgs.CreateCluster switch planID { case "885a1cb6-ca42-43e9-a725-8195918e1343": req.MetricsFlag = true - req.ContainerResources = "osbsmall" + req.CPULimit = "1.0" + req.CPURequest = "0.1" + req.MemoryLimit = "512Mi" + req.MemoryRequest = "512Mi" req.StorageConfig = "osbsmall" case "dc951396-bb28-45a4-b040-cfe3bebc6121": req.MetricsFlag = true - req.ContainerResources = "osbmedium" + req.CPULimit = "2.0" + req.CPURequest = "0.5" + req.MemoryLimit = "1Gi" + req.MemoryRequest = "1Gi" req.StorageConfig = "osbmedium" case "04349656-4dc9-4b67-9b15-52a93d64d566": req.MetricsFlag = true - req.ContainerResources = "osblarge" + req.CPULimit = "4.0" + req.CPURequest = "1.0" + req.MemoryLimit = "2Gi" + req.MemoryRequest = "2Gi" req.StorageConfig = "osblarge" case "877432f8-07eb-4e57-b984-d025a71d2282": req.MetricsFlag = true req.ReplicaCount = 1 - req.ContainerResources = "osbsmall" + req.CPULimit = "1.0" + req.CPURequest = "0.1" + req.MemoryLimit = "512Mi" + req.MemoryRequest = "512Mi" req.StorageConfig = "osbsmall" case "89bcdf8a-e637-4bb3-b7ce-aca083cc1e69": req.MetricsFlag = true req.ReplicaCount = 1 - req.ContainerResources = "osbmedium" + req.CPULimit = "2.0" + req.CPURequest = "0.5" + req.MemoryLimit = "1Gi" + req.MemoryRequest = "1Gi" req.StorageConfig = "osbmedium" case "470ca1a0-2763-41f1-a4cf-985acdb549ab": req.MetricsFlag = true req.ReplicaCount = 1 - req.ContainerResources = "osblarge" + req.CPULimit = "4.0" + req.CPURequest = "1.0" + req.MemoryLimit = "2Gi" + req.MemoryRequest = "2Gi" req.StorageConfig = "osblarge" default: return @@ -267,12 +288,11 @@ func (po *PGOperator) CreateBinding(instanceID, bindID, appID string) (BasicCred log.Println("no users found") return BasicCred{}, errors.New("no users found for instance " + instanceID) } - users := suResp.Results[0] + users := suResp.Results log.Println("cluster secrets are:") credentials := make(map[string]interface{}) - for _, s := range users.Secrets { + for _, s := range users { if os.Getenv("CRUNCHY_DEBUG") == "true" { - log.Println("secret : " + s.Name) log.Println("username: " + s.Username) log.Println("password: " + s.Password) } @@ -331,7 +351,7 @@ func (po *PGOperator) ClusterDetail(instanceID string) (ClusterDetails, error) { detail := &response.Results[0] replicaCount, err := strconv.Atoi(detail.Cluster.Spec.Replicas) if err != nil { - return noInfo, fmt.Errorf("invalid replica count %s in cluster spec, unable to convert to int: %s", + return noInfo, fmt.Errorf("invalid replica count %s in cluster spec, unable to convert to int: %s", detail.Cluster.Spec.Replicas, err) } if l := len(detail.Services); (replicaCount == 0 && l != 1) || (replicaCount > 0 && l != 2) { @@ -361,7 +381,6 @@ func (po *PGOperator) CreateCluster(req CreateRequest) error { ClientVersion: po.clientVer, Name: req.Name, Namespace: req.Namespace, - Series: 1, UserLabels: po.instLabel(req.InstanceID), } po.createRequestByPlan(req.PlanID, r) @@ -376,9 +395,7 @@ func (po *PGOperator) CreateCluster(req CreateRequest) error { log.Println("create cluster non-Ok status: ", response.Msg) return errors.New(response.Msg) } else { - for _, v := range response.Results { - log.Println(v) - } + log.Println(response.Result) } return nil @@ -462,8 +479,8 @@ func (po *PGOperator) DeleteCluster(instanceID string) error { log.Println("no users found, expected default users") return errors.New("unexpected user state: no default users " + instanceID) } - users := suResp.Results[0] - for _, s := range users.Secrets { + users := suResp.Results + for _, s := range users { if strings.Compare("user", s.Username[:4]) == 0 { return ErrBindingsRemain }