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/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= 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 } } 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