Skip to content

Commit

Permalink
Merge pull request #108 from 3scale-ops/fix/deployment-replicas-defau…
Browse files Browse the repository at this point in the history
…lting

fix: deployment replicas defaulting
  • Loading branch information
3scale-robot authored Jun 7, 2021
2 parents 77c300b + f57d830 commit b41e7b9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions bundle/manifests/saas-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3425,4 +3425,4 @@ spec:
provider:
name: Red Hat
url: https://www.3scale.net/
version: 0.9.10
version: 0.9.11
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/3scale/saas-operator
newTag: 0.9.10
newTag: 0.9.11
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
35 changes: 33 additions & 2 deletions pkg/basereconciler/reconcile_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package version

const (
version string = "v0.9.10"
version string = "v0.9.11"
)

// Current returns the current marin3r operator version
Expand Down

0 comments on commit b41e7b9

Please sign in to comment.