From c61e465d284ec04e30e668e9be84c2ed2505b909 Mon Sep 17 00:00:00 2001 From: Rael Garcia Date: Thu, 3 Jun 2021 10:48:34 +0200 Subject: [PATCH 1/5] fix: use current replica count during dep reconcile --- pkg/basereconciler/reconcile_resources.go | 35 +++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/pkg/basereconciler/reconcile_resources.go b/pkg/basereconciler/reconcile_resources.go index c505304c..63d97a9e 100644 --- a/pkg/basereconciler/reconcile_resources.go +++ b/pkg/basereconciler/reconcile_resources.go @@ -161,6 +161,29 @@ type GrafanaDashboard struct { Enabled bool } +// GetDeploymentReplicas returns the number of replicas for a deployment, +// current value if HPA is enabled. +func (r *Reconciler) GetDeploymentReplicas(ctx context.Context, d Deployment) (*int32, error) { + + dep := d.Template().(*appsv1.Deployment) + if !d.HasHPA { + return dep.Spec.Replicas, nil + } + key := types.NamespacedName{ + Name: dep.GetName(), + Namespace: dep.GetNamespace(), + } + instance := &appsv1.Deployment{} + err := r.GetClient().Get(ctx, key, instance) + if err != nil { + if errors.IsNotFound(err) { + return dep.Spec.Replicas, nil + } + return dep.Spec.Replicas, err + } + return instance.Spec.Replicas, nil +} + // ReconcileOwnedResources handles generalized resource reconcile logic for // all controllers func (r *Reconciler) ReconcileOwnedResources(ctx context.Context, owner client.Object, crs ControlledResources) error { @@ -169,9 +192,14 @@ func (r *Reconciler) ReconcileOwnedResources(ctx context.Context, owner client.O for _, dep := range crs.Deployments { + currentReplicas, err := r.GetDeploymentReplicas(ctx, dep) + if err != nil { + return err + } + resources = append(resources, LockedResource{ - GeneratorFn: r.DeploymentWithRolloutTriggers(dep.Template, dep.RolloutTriggers), + GeneratorFn: r.DeploymentWithRolloutTriggers(dep.Template, dep.RolloutTriggers, currentReplicas), ExcludePaths: func() []string { if dep.HasHPA { return append(DeploymentExcludedPaths, "/spec/replicas") @@ -272,7 +300,7 @@ func ServiceExcludes(fn GeneratorFunction) []string { } // DeploymentWithRolloutTriggers returns the Deployment modified with the appropriate rollout triggers (annotations) -func (r *Reconciler) DeploymentWithRolloutTriggers(deployment GeneratorFunction, triggers []RolloutTrigger) GeneratorFunction { +func (r *Reconciler) DeploymentWithRolloutTriggers(deployment GeneratorFunction, triggers []RolloutTrigger, replicas *int32) GeneratorFunction { return func() client.Object { dep := deployment().(*appsv1.Deployment) @@ -282,6 +310,9 @@ func (r *Reconciler) DeploymentWithRolloutTriggers(deployment GeneratorFunction, for _, trigger := range triggers { dep.Spec.Template.ObjectMeta.Annotations[trigger.GetAnnotationKey()] = trigger.GetHash() } + + dep.Spec.Replicas = replicas + return dep } } From 08386f89eb4a52a7ff0e2a5e5d345e38b8528633 Mon Sep 17 00:00:00 2001 From: Rael Garcia Date: Thu, 3 Jun 2021 11:57:23 +0200 Subject: [PATCH 2/5] config: bump version to 0.9.11 --- Makefile | 2 +- bundle/manifests/saas-operator.clusterserviceversion.yaml | 6 +++--- config/manager/kustomization.yaml | 2 +- pkg/version/version.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7e3e2e48..6607bb91 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SHELL:=/bin/bash # Current Operator version -VERSION ?= 0.9.10 +VERSION ?= 0.9.11 # Default catalog image CATALOG_IMG ?= quay.io/3scaleops/saas-operator-bundle:catalog # Default bundle image tag diff --git a/bundle/manifests/saas-operator.clusterserviceversion.yaml b/bundle/manifests/saas-operator.clusterserviceversion.yaml index 848475fc..ed2ff06b 100644 --- a/bundle/manifests/saas-operator.clusterserviceversion.yaml +++ b/bundle/manifests/saas-operator.clusterserviceversion.yaml @@ -585,7 +585,7 @@ metadata: operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/3scale/saas-operator support: Red Hat - name: saas-operator.v0.9.10 + name: saas-operator.v0.9.11 namespace: placeholder spec: apiservicedefinitions: {} @@ -3038,7 +3038,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.annotations['olm.targetNamespaces'] - image: quay.io/3scale/saas-operator:0.9.10 + image: quay.io/3scale/saas-operator:0.9.11 livenessProbe: httpGet: path: /healthz @@ -3425,4 +3425,4 @@ spec: provider: name: Red Hat url: https://www.3scale.net/ - version: 0.9.10 + version: 0.9.11 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index fc4f073a..6298c41b 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -13,4 +13,4 @@ kind: Kustomization images: - name: controller newName: quay.io/3scale/saas-operator - newTag: 0.9.10 + newTag: 0.9.11 diff --git a/pkg/version/version.go b/pkg/version/version.go index 3804ec09..21e50296 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,7 +1,7 @@ package version const ( - version string = "v0.9.10" + version string = "v0.9.11" ) // Current returns the current marin3r operator version From 3a9f61649c8ac75889004f7e2847b55a0c76cd81 Mon Sep 17 00:00:00 2001 From: Rael Garcia Date: Fri, 4 Jun 2021 10:52:16 +0200 Subject: [PATCH 3/5] feat: alpha bundle --- bundle.Dockerfile | 4 +--- bundle/metadata/annotations.yaml | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bundle.Dockerfile b/bundle.Dockerfile index 346f9e6f..ab793deb 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -4,14 +4,12 @@ LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=saas-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha,stable -LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha +LABEL operators.operatorframework.io.bundle.channels.v1=alpha LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.3.2 LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 - COPY bundle/manifests /manifests/ COPY bundle/metadata /metadata/ COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index 51ba9929..e181db47 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -1,6 +1,5 @@ annotations: - operators.operatorframework.io.bundle.channel.default.v1: alpha - operators.operatorframework.io.bundle.channels.v1: alpha,stable + operators.operatorframework.io.bundle.channels.v1: alpha operators.operatorframework.io.bundle.manifests.v1: manifests/ operators.operatorframework.io.bundle.mediatype.v1: registry+v1 operators.operatorframework.io.bundle.metadata.v1: metadata/ From a71d5d0e82056bc57db6cc4e2e8e16e795a8fa7a Mon Sep 17 00:00:00 2001 From: Roi Vazquez Date: Mon, 7 Jun 2021 11:19:54 +0200 Subject: [PATCH 4/5] Point to the correct operator-utils version --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 929fe084..b4ff721d 100644 --- a/go.mod +++ b/go.mod @@ -11,12 +11,10 @@ require ( github.com/onsi/gomega v1.10.2 github.com/openshift/api v3.9.0+incompatible github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.42.1 - github.com/redhat-cop/operator-utils v1.1.1 + github.com/redhat-cop/operator-utils v1.1.3-0.20210602122509-2eaf121122d2 k8s.io/api v0.20.0 k8s.io/apimachinery v0.20.0 k8s.io/client-go v0.20.0 k8s.io/utils v0.0.0-20201110183641-67b214c5f920 sigs.k8s.io/controller-runtime v0.7.0 ) - -replace github.com/redhat-cop/operator-utils v1.1.2 => github.com/roivaz/operator-utils v1.1.3-0.20210601154758-2d8356946ef8 diff --git a/go.sum b/go.sum index ec13e6e2..0fbbc40c 100644 --- a/go.sum +++ b/go.sum @@ -459,8 +459,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.2.0 h1:wH4vA7pcjKuZzjF7lM8awk4fnuJO6idemZXoKnULUx4= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/redhat-cop/operator-utils v1.1.1 h1:CxLj3ZHs36Zzbjw05couZlR08Gd7PcE49DeCD+sqYFw= -github.com/redhat-cop/operator-utils v1.1.1/go.mod h1:d/7g1ZoiKNDjRjgUsqn7jzrWHKNCX2RNDbPmgXUgJN0= +github.com/redhat-cop/operator-utils v1.1.3-0.20210602122509-2eaf121122d2 h1:m0IMqkR8PcFAXITvUZGHTte/NvyF/P4Qr3bw0eIw2+c= +github.com/redhat-cop/operator-utils v1.1.3-0.20210602122509-2eaf121122d2/go.mod h1:Hu6OKop6iQfga0Hwrqv/03CQgpkcp55qwjMh9Gi0Iyk= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= From f57d8308977c605606ac06e5dbc8f61ce6fcde83 Mon Sep 17 00:00:00 2001 From: Roi Vazquez Date: Mon, 7 Jun 2021 11:28:36 +0200 Subject: [PATCH 5/5] Release into stable --- bundle.Dockerfile | 4 +++- bundle/metadata/annotations.yaml | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bundle.Dockerfile b/bundle.Dockerfile index ab793deb..346f9e6f 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -4,12 +4,14 @@ LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=saas-operator -LABEL operators.operatorframework.io.bundle.channels.v1=alpha +LABEL operators.operatorframework.io.bundle.channels.v1=alpha,stable +LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.3.2 LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/ LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 + COPY bundle/manifests /manifests/ COPY bundle/metadata /metadata/ COPY bundle/tests/scorecard /tests/scorecard/ diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index e181db47..51ba9929 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -1,5 +1,6 @@ annotations: - operators.operatorframework.io.bundle.channels.v1: alpha + operators.operatorframework.io.bundle.channel.default.v1: alpha + operators.operatorframework.io.bundle.channels.v1: alpha,stable operators.operatorframework.io.bundle.manifests.v1: manifests/ operators.operatorframework.io.bundle.mediatype.v1: registry+v1 operators.operatorframework.io.bundle.metadata.v1: metadata/