diff --git a/Makefile b/Makefile index 363a1fde..46962abb 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SHELL := /bin/bash # Current Operator version -VERSION ?= 0.4.0 +VERSION ?= 0.5.0 # Default bundle image tag BUNDLE_IMG ?= controller-bundle:$(VERSION) # Options for 'bundle-build' diff --git a/README.md b/README.md index 4b51655c..a14f7aa5 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Table of Contents * [Red Hat Certified Images](#red-hat-certified-images) * [Image Pull Policy](#image-pull-policy) * [Repositories Auto Creation](#repositories-auto-creation) + * [Scaling](#scaling) * [Contributing](#contributing) @@ -413,6 +414,37 @@ All of these repositories will be also added to the `maven-public` group. This g All of these operations are disabled if the attribute `spec.generateRandomAdminPassword` is set to `true`, since default credentials are needed to create the `nexus-operator` user. You can safely change the default credentials after this user has been created. +## Scaling + +For now, the Nexus Operator won't accept a number higher than `1` to the `spec.replicas` attribute. +This is because the Nexus server can't share its mounted persistent volume with other pods. See #191 for more details. + +Horizontal scaling will only work once we add [HA support](https://help.sonatype.com/repomanager3/high-availability) to the operator (see #61). +If you need to scale the server, you should take the vertical approach and increase the numbers of resource limits used +by the Nexus server. For example: + +```yaml +apiVersion: apps.m88i.io/v1alpha1 +kind: Nexus +metadata: + name: nexus3 +spec: + replicas: 1 + # Set the resources requests and limits for Nexus pods. See: https://help.sonatype.com/repomanager3/system-requirements + resources: + limits: + cpu: "4" + memory: "8Gi" + requests: + cpu: "1" + memory: "2Gi" + persistence: + persistent: true + volumeSize: 10Gi +``` + +We are working to support HA in the future. + ## Contributing Please read our [Contribution Guide](CONTRIBUTING.md). diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b0d31f45..02d276ea 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,8 +1,6 @@ -## Version 0.4.0 +## Version 0.5.0 ### Enhancements -- #161 - Nexus Operator is now cluster-scoped, meaning that you can install the operator and the Nexus CRs in separated namespaces. See [Operator Scopes](https://sdk.operatorframework.io/docs/building-operators/golang/operator-scope/) for more information. - ### Bug Fixes -- #157 - When installing the operator and the Nexus CR in different namespaces, the server operations performed in the Nexus API by the operator won't work. \ No newline at end of file +- #191 - Pod fails to start after modifying the Nexus resource diff --git a/bundle/manifests/nexus-operator.clusterserviceversion.yaml b/bundle/manifests/nexus-operator.clusterserviceversion.yaml index 8b2f7e7e..23ce5cdb 100644 --- a/bundle/manifests/nexus-operator.clusterserviceversion.yaml +++ b/bundle/manifests/nexus-operator.clusterserviceversion.yaml @@ -35,7 +35,7 @@ metadata: capabilities: Seamless Upgrades categories: Developer Tools certified: "false" - containerImage: quay.io/m88i/nexus-operator:0.4.0 + containerImage: quay.io/m88i/nexus-operator:0.5.0 createdAt: "2019-11-16T13:12:22Z" description: Nexus Operator to deploy and manage Nexus 3.x servers operators.operatorframework.io/builder: operator-sdk-v1.0.1 @@ -43,7 +43,7 @@ metadata: repository: https://github.com/m88i/nexus-operator support: m88i Labs tectonic-visibility: ocs - name: nexus-operator.v0.4.0 + name: nexus-operator.v0.5.0 namespace: placeholder spec: apiservicedefinitions: {} @@ -214,17 +214,6 @@ spec: control-plane: controller-manager spec: containers: - - args: - - --metrics-addr=127.0.0.1:8080 - - --enable-leader-election - command: - - /manager - image: quay.io/m88i/nexus-operator:0.4.0 - name: manager - resources: - requests: - cpu: 100m - memory: 20Mi - args: - --secure-listen-address=0.0.0.0:8443 - --upstream=http://127.0.0.1:8080/ @@ -236,6 +225,17 @@ spec: - containerPort: 8443 name: https resources: {} + - args: + - --metrics-addr=127.0.0.1:8080 + - --enable-leader-election + command: + - /manager + image: quay.io/m88i/nexus-operator:0.5.0 + name: manager + resources: + requests: + cpu: 100m + memory: 20Mi terminationGracePeriodSeconds: 10 permissions: - rules: @@ -301,5 +301,5 @@ spec: maturity: alpha provider: name: m88i Labs - replaces: nexus-operator.v0.3.0 - version: 0.4.0 + replaces: nexus-operator.v0.4.0 + version: 0.5.0 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index c2f8e2ea..6a0cd6c1 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -5,4 +5,4 @@ kind: Kustomization images: - name: controller newName: quay.io/m88i/nexus-operator - newTag: 0.4.0 + newTag: 0.5.0 diff --git a/config/manifests/bases/nexus-operator.clusterserviceversion.yaml b/config/manifests/bases/nexus-operator.clusterserviceversion.yaml index 32265b26..b7530fc7 100644 --- a/config/manifests/bases/nexus-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/nexus-operator.clusterserviceversion.yaml @@ -35,7 +35,7 @@ metadata: capabilities: Seamless Upgrades categories: Developer Tools certified: "false" - containerImage: quay.io/m88i/nexus-operator:0.4.0 + containerImage: quay.io/m88i/nexus-operator:0.5.0 createdAt: "2019-11-16T13:12:22Z" description: Nexus Operator to deploy and manage Nexus 3.x servers operators.operatorframework.io/builder: operator-sdk-v1.0.1 @@ -43,7 +43,7 @@ metadata: repository: https://github.com/m88i/nexus-operator support: m88i Labs tectonic-visibility: ocs - name: nexus-operator.v0.4.0 + name: nexus-operator.v0.5.0 namespace: placeholder spec: apiservicedefinitions: {} @@ -296,5 +296,5 @@ spec: maturity: alpha provider: name: m88i Labs - replaces: nexus-operator.v0.3.0 - version: 0.4.0 + replaces: nexus-operator.v0.4.0 + version: 0.5.0 diff --git a/controllers/nexus/resource/deployment/deployment.go b/controllers/nexus/resource/deployment/deployment.go index 85deed53..a7823d36 100644 --- a/controllers/nexus/resource/deployment/deployment.go +++ b/controllers/nexus/resource/deployment/deployment.go @@ -68,6 +68,9 @@ func newDeployment(nexus *v1alpha1.Nexus) *appsv1.Deployment { Selector: &metav1.LabelSelector{ MatchLabels: meta.GenerateLabels(nexus), }, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.RecreateDeploymentStrategyType, + }, Template: corev1.PodTemplateSpec{ ObjectMeta: meta.DefaultObjectMeta(nexus), Spec: corev1.PodSpec{ diff --git a/controllers/nexus/resource/validation/defaults.go b/controllers/nexus/resource/validation/defaults.go index e5978ec9..219f550f 100644 --- a/controllers/nexus/resource/validation/defaults.go +++ b/controllers/nexus/resource/validation/defaults.go @@ -33,6 +33,8 @@ const ( probeDefaultPeriodSeconds = int32(10) probeDefaultSuccessThreshold = int32(1) probeDefaultFailureThreshold = int32(3) + + maxReplicas = int32(1) ) var ( diff --git a/controllers/nexus/resource/validation/validation.go b/controllers/nexus/resource/validation/validation.go index 3ad5500a..0bca6525 100644 --- a/controllers/nexus/resource/validation/validation.go +++ b/controllers/nexus/resource/validation/validation.go @@ -133,11 +133,19 @@ func (v *Validator) setDefaults(nexus *v1alpha1.Nexus) *v1alpha1.Nexus { } func (v *Validator) setDeploymentDefaults(nexus *v1alpha1.Nexus) { + v.setReplicasDefaults(nexus) v.setResourcesDefaults(nexus) v.setImageDefaults(nexus) v.setProbeDefaults(nexus) } +func (v *Validator) setReplicasDefaults(nexus *v1alpha1.Nexus) { + if nexus.Spec.Replicas > maxReplicas { + v.log.Warn("Number of replicas not supported", "MaxSupportedReplicas", maxReplicas, "DesiredReplicas", nexus.Spec.Replicas) + nexus.Spec.Replicas = ensureMaximum(nexus.Spec.Replicas, maxReplicas) + } +} + func (v *Validator) setResourcesDefaults(nexus *v1alpha1.Nexus) { if nexus.Spec.Resources.Requests == nil && nexus.Spec.Resources.Limits == nil { nexus.Spec.Resources = DefaultResources @@ -287,3 +295,10 @@ func ensureMinimum(value, minimum int32) int32 { } return value } + +func ensureMaximum(value, max int32) int32 { + if value > max { + return max + } + return value +} diff --git a/controllers/nexus/resource/validation/validation_test.go b/controllers/nexus/resource/validation/validation_test.go index b7aa9400..0105e570 100644 --- a/controllers/nexus/resource/validation/validation_test.go +++ b/controllers/nexus/resource/validation/validation_test.go @@ -189,6 +189,19 @@ func TestValidator_SetDefaultsAndValidate_Deployment(t *testing.T) { }(), AllDefaultsCommunityNexus.DeepCopy(), }, + { + "Invalid 'spec.replicas'", + func() *v1alpha1.Nexus { + nexus := AllDefaultsCommunityNexus.DeepCopy() + nexus.Spec.Replicas = 3 + return nexus + }(), + func() *v1alpha1.Nexus { + nexus := AllDefaultsCommunityNexus.DeepCopy() + nexus.Spec.Replicas = 1 + return nexus + }(), + }, } for _, tt := range tests { diff --git a/nexus-operator.yaml b/nexus-operator.yaml index f3db4a34..6b409db9 100644 --- a/nexus-operator.yaml +++ b/nexus-operator.yaml @@ -598,17 +598,6 @@ spec: control-plane: controller-manager spec: containers: - - args: - - --metrics-addr=127.0.0.1:8080 - - --enable-leader-election - command: - - /manager - image: quay.io/m88i/nexus-operator:0.4.0 - name: manager - resources: - requests: - cpu: 100m - memory: 20Mi - args: - --secure-listen-address=0.0.0.0:8443 - --upstream=http://127.0.0.1:8080/ @@ -619,6 +608,17 @@ spec: ports: - containerPort: 8443 name: https + - args: + - --metrics-addr=127.0.0.1:8080 + - --enable-leader-election + command: + - /manager + image: quay.io/m88i/nexus-operator:0.5.0 + name: manager + resources: + requests: + cpu: 100m + memory: 20Mi terminationGracePeriodSeconds: 10 --- apiVersion: monitoring.coreos.com/v1