From 7f156f419087d4bceaad2578b161c258ee5b41dc Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Wed, 9 Dec 2020 18:49:46 -0300 Subject: [PATCH 1/4] Fix #191 - Changing deployment strategy to recreate and setting replicas to max 1 Signed-off-by: Ricardo Zanini --- Makefile | 2 +- README.md | 32 +++++++++++++++++ RELEASE_NOTES.md | 6 ++-- api/v1alpha1/zz_generated.openapi.go | 34 +++++++++---------- .../nexus-operator.clusterserviceversion.yaml | 10 +++--- config/manager/kustomization.yaml | 2 +- .../nexus-operator.clusterserviceversion.yaml | 8 ++--- .../nexus/resource/deployment/deployment.go | 3 ++ .../nexus/resource/validation/validation.go | 23 ++++++++++++- .../resource/validation/validation_test.go | 13 +++++++ nexus-operator.yaml | 2 +- 11 files changed, 101 insertions(+), 34 deletions(-) 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..4acb52dd 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 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/api/v1alpha1/zz_generated.openapi.go b/api/v1alpha1/zz_generated.openapi.go index 522877e4..ad1e9e6d 100644 --- a/api/v1alpha1/zz_generated.openapi.go +++ b/api/v1alpha1/zz_generated.openapi.go @@ -26,14 +26,14 @@ import ( func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ - "./api/v1alpha1.NexusPersistence": schema__api_v1alpha1_NexusPersistence(ref), - "./api/v1alpha1.NexusProbe": schema__api_v1alpha1_NexusProbe(ref), - "./api/v1alpha1.NexusSpec": schema__api_v1alpha1_NexusSpec(ref), - "./api/v1alpha1.NexusStatus": schema__api_v1alpha1_NexusStatus(ref), + "github.com/m88i/nexus-operator/api/v1alpha1.NexusPersistence": schema_m88i_nexus_operator_api_v1alpha1_NexusPersistence(ref), + "github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe": schema_m88i_nexus_operator_api_v1alpha1_NexusProbe(ref), + "github.com/m88i/nexus-operator/api/v1alpha1.NexusSpec": schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref), + "github.com/m88i/nexus-operator/api/v1alpha1.NexusStatus": schema_m88i_nexus_operator_api_v1alpha1_NexusStatus(ref), } } -func schema__api_v1alpha1_NexusPersistence(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_m88i_nexus_operator_api_v1alpha1_NexusPersistence(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -68,7 +68,7 @@ func schema__api_v1alpha1_NexusPersistence(ref common.ReferenceCallback) common. } } -func schema__api_v1alpha1_NexusProbe(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_m88i_nexus_operator_api_v1alpha1_NexusProbe(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -116,7 +116,7 @@ func schema__api_v1alpha1_NexusProbe(ref common.ReferenceCallback) common.OpenAP } } -func schema__api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -140,7 +140,7 @@ func schema__api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPI "automaticUpdate": { SchemaProps: spec.SchemaProps{ Description: "Automatic updates configuration", - Ref: ref("./api/v1alpha1.NexusAutomaticUpdate"), + Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusAutomaticUpdate"), }, }, "imagePullPolicy": { @@ -159,7 +159,7 @@ func schema__api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPI "persistence": { SchemaProps: spec.SchemaProps{ Description: "Persistence definition", - Ref: ref("./api/v1alpha1.NexusPersistence"), + Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusPersistence"), }, }, "useRedHatImage": { @@ -179,7 +179,7 @@ func schema__api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPI "networking": { SchemaProps: spec.SchemaProps{ Description: "Networking definition", - Ref: ref("./api/v1alpha1.NexusNetworking"), + Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusNetworking"), }, }, "serviceAccountName": { @@ -192,19 +192,19 @@ func schema__api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPI "livenessProbe": { SchemaProps: spec.SchemaProps{ Description: "LivenessProbe describes how the Nexus container liveness probe should work", - Ref: ref("./api/v1alpha1.NexusProbe"), + Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe"), }, }, "readinessProbe": { SchemaProps: spec.SchemaProps{ Description: "ReadinessProbe describes how the Nexus container readiness probe should work", - Ref: ref("./api/v1alpha1.NexusProbe"), + Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe"), }, }, "serverOperations": { SchemaProps: spec.SchemaProps{ Description: "ServerOperations describes the options for the operations performed on the deployed server instance", - Ref: ref("./api/v1alpha1.ServerOperationsOpts"), + Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.ServerOperationsOpts"), }, }, }, @@ -212,11 +212,11 @@ func schema__api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPI }, }, Dependencies: []string{ - "./api/v1alpha1.NexusAutomaticUpdate", "./api/v1alpha1.NexusNetworking", "./api/v1alpha1.NexusPersistence", "./api/v1alpha1.NexusProbe", "./api/v1alpha1.ServerOperationsOpts", "k8s.io/api/core/v1.ResourceRequirements"}, + "github.com/m88i/nexus-operator/api/v1alpha1.NexusAutomaticUpdate", "github.com/m88i/nexus-operator/api/v1alpha1.NexusNetworking", "github.com/m88i/nexus-operator/api/v1alpha1.NexusPersistence", "github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe", "github.com/m88i/nexus-operator/api/v1alpha1.ServerOperationsOpts", "k8s.io/api/core/v1.ResourceRequirements"}, } } -func schema__api_v1alpha1_NexusStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_m88i_nexus_operator_api_v1alpha1_NexusStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -272,13 +272,13 @@ func schema__api_v1alpha1_NexusStatus(ref common.ReferenceCallback) common.OpenA "serverOperationsStatus": { SchemaProps: spec.SchemaProps{ Description: "ServerOperationsStatus describes the general status for the operations performed in the Nexus server instance", - Ref: ref("./api/v1alpha1.OperationsStatus"), + Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.OperationsStatus"), }, }, }, }, }, Dependencies: []string{ - "./api/v1alpha1.OperationsStatus", "k8s.io/api/apps/v1.DeploymentStatus"}, + "github.com/m88i/nexus-operator/api/v1alpha1.OperationsStatus", "k8s.io/api/apps/v1.DeploymentStatus"}, } } diff --git a/bundle/manifests/nexus-operator.clusterserviceversion.yaml b/bundle/manifests/nexus-operator.clusterserviceversion.yaml index 8b2f7e7e..9e1f8aee 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: {} @@ -219,7 +219,7 @@ spec: - --enable-leader-election command: - /manager - image: quay.io/m88i/nexus-operator:0.4.0 + image: quay.io/m88i/nexus-operator:0.5.0 name: manager resources: requests: @@ -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/validation.go b/controllers/nexus/resource/validation/validation.go index 3ad5500a..5d24e77a 100644 --- a/controllers/nexus/resource/validation/validation.go +++ b/controllers/nexus/resource/validation/validation.go @@ -80,7 +80,21 @@ func (v *Validator) SetDefaultsAndValidate(nexus *v1alpha1.Nexus) (*v1alpha1.Nex } func (v *Validator) validate(nexus *v1alpha1.Nexus) error { - return v.validateNetworking(nexus) + validators := []func(*v1alpha1.Nexus) error{v.validateDeployment, v.validateNetworking} + for _, v := range validators { + if err := v(nexus); err != nil { + return err + } + } + return nil +} + +func (v *Validator) validateDeployment(nexus *v1alpha1.Nexus) error { + if nexus.Spec.Replicas > 1 { + v.log.Warn("Nexus server only supports 1 replica.", "Desired Replicas", nexus.Spec.Replicas) + nexus.Spec.Replicas = ensureMaximum(nexus.Spec.Replicas, 1) + } + return nil } func (v *Validator) validateNetworking(nexus *v1alpha1.Nexus) error { @@ -287,3 +301,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..b2c4a71f 100644 --- a/nexus-operator.yaml +++ b/nexus-operator.yaml @@ -603,7 +603,7 @@ spec: - --enable-leader-election command: - /manager - image: quay.io/m88i/nexus-operator:0.4.0 + image: quay.io/m88i/nexus-operator:0.5.0 name: manager resources: requests: From 7736fecc3b40dbb05794b79cca92104161a9dc02 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Wed, 9 Dec 2020 18:57:53 -0300 Subject: [PATCH 2/4] reverting back openapi gen files Signed-off-by: Ricardo Zanini --- api/v1alpha1/zz_generated.openapi.go | 34 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/api/v1alpha1/zz_generated.openapi.go b/api/v1alpha1/zz_generated.openapi.go index ad1e9e6d..522877e4 100644 --- a/api/v1alpha1/zz_generated.openapi.go +++ b/api/v1alpha1/zz_generated.openapi.go @@ -26,14 +26,14 @@ import ( func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ - "github.com/m88i/nexus-operator/api/v1alpha1.NexusPersistence": schema_m88i_nexus_operator_api_v1alpha1_NexusPersistence(ref), - "github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe": schema_m88i_nexus_operator_api_v1alpha1_NexusProbe(ref), - "github.com/m88i/nexus-operator/api/v1alpha1.NexusSpec": schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref), - "github.com/m88i/nexus-operator/api/v1alpha1.NexusStatus": schema_m88i_nexus_operator_api_v1alpha1_NexusStatus(ref), + "./api/v1alpha1.NexusPersistence": schema__api_v1alpha1_NexusPersistence(ref), + "./api/v1alpha1.NexusProbe": schema__api_v1alpha1_NexusProbe(ref), + "./api/v1alpha1.NexusSpec": schema__api_v1alpha1_NexusSpec(ref), + "./api/v1alpha1.NexusStatus": schema__api_v1alpha1_NexusStatus(ref), } } -func schema_m88i_nexus_operator_api_v1alpha1_NexusPersistence(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema__api_v1alpha1_NexusPersistence(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -68,7 +68,7 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusPersistence(ref common.Referen } } -func schema_m88i_nexus_operator_api_v1alpha1_NexusProbe(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema__api_v1alpha1_NexusProbe(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -116,7 +116,7 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusProbe(ref common.ReferenceCall } } -func schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema__api_v1alpha1_NexusSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -140,7 +140,7 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref common.ReferenceCallb "automaticUpdate": { SchemaProps: spec.SchemaProps{ Description: "Automatic updates configuration", - Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusAutomaticUpdate"), + Ref: ref("./api/v1alpha1.NexusAutomaticUpdate"), }, }, "imagePullPolicy": { @@ -159,7 +159,7 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref common.ReferenceCallb "persistence": { SchemaProps: spec.SchemaProps{ Description: "Persistence definition", - Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusPersistence"), + Ref: ref("./api/v1alpha1.NexusPersistence"), }, }, "useRedHatImage": { @@ -179,7 +179,7 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref common.ReferenceCallb "networking": { SchemaProps: spec.SchemaProps{ Description: "Networking definition", - Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusNetworking"), + Ref: ref("./api/v1alpha1.NexusNetworking"), }, }, "serviceAccountName": { @@ -192,19 +192,19 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref common.ReferenceCallb "livenessProbe": { SchemaProps: spec.SchemaProps{ Description: "LivenessProbe describes how the Nexus container liveness probe should work", - Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe"), + Ref: ref("./api/v1alpha1.NexusProbe"), }, }, "readinessProbe": { SchemaProps: spec.SchemaProps{ Description: "ReadinessProbe describes how the Nexus container readiness probe should work", - Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe"), + Ref: ref("./api/v1alpha1.NexusProbe"), }, }, "serverOperations": { SchemaProps: spec.SchemaProps{ Description: "ServerOperations describes the options for the operations performed on the deployed server instance", - Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.ServerOperationsOpts"), + Ref: ref("./api/v1alpha1.ServerOperationsOpts"), }, }, }, @@ -212,11 +212,11 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusSpec(ref common.ReferenceCallb }, }, Dependencies: []string{ - "github.com/m88i/nexus-operator/api/v1alpha1.NexusAutomaticUpdate", "github.com/m88i/nexus-operator/api/v1alpha1.NexusNetworking", "github.com/m88i/nexus-operator/api/v1alpha1.NexusPersistence", "github.com/m88i/nexus-operator/api/v1alpha1.NexusProbe", "github.com/m88i/nexus-operator/api/v1alpha1.ServerOperationsOpts", "k8s.io/api/core/v1.ResourceRequirements"}, + "./api/v1alpha1.NexusAutomaticUpdate", "./api/v1alpha1.NexusNetworking", "./api/v1alpha1.NexusPersistence", "./api/v1alpha1.NexusProbe", "./api/v1alpha1.ServerOperationsOpts", "k8s.io/api/core/v1.ResourceRequirements"}, } } -func schema_m88i_nexus_operator_api_v1alpha1_NexusStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema__api_v1alpha1_NexusStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -272,13 +272,13 @@ func schema_m88i_nexus_operator_api_v1alpha1_NexusStatus(ref common.ReferenceCal "serverOperationsStatus": { SchemaProps: spec.SchemaProps{ Description: "ServerOperationsStatus describes the general status for the operations performed in the Nexus server instance", - Ref: ref("github.com/m88i/nexus-operator/api/v1alpha1.OperationsStatus"), + Ref: ref("./api/v1alpha1.OperationsStatus"), }, }, }, }, }, Dependencies: []string{ - "github.com/m88i/nexus-operator/api/v1alpha1.OperationsStatus", "k8s.io/api/apps/v1.DeploymentStatus"}, + "./api/v1alpha1.OperationsStatus", "k8s.io/api/apps/v1.DeploymentStatus"}, } } From b2a44723fee3bf5ef07ec030cf05bd0bb9f45965 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:25:05 -0300 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Lucas Caparelli --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4acb52dd..a14f7aa5 100644 --- a/README.md +++ b/README.md @@ -419,7 +419,7 @@ All of these operations are disabled if the attribute `spec.generateRandomAdminP 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 to the operator (see #61). +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: From 301877de6ec74bbc4939b04aa0dd75bc874059ed Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Sun, 13 Dec 2020 13:11:48 -0300 Subject: [PATCH 4/4] Move mutability to defaults Signed-off-by: Ricardo Zanini --- .../nexus-operator.clusterserviceversion.yaml | 22 ++++++++--------- .../nexus/resource/validation/defaults.go | 2 ++ .../nexus/resource/validation/validation.go | 24 +++++++------------ nexus-operator.yaml | 20 ++++++++-------- 4 files changed, 32 insertions(+), 36 deletions(-) diff --git a/bundle/manifests/nexus-operator.clusterserviceversion.yaml b/bundle/manifests/nexus-operator.clusterserviceversion.yaml index 9e1f8aee..23ce5cdb 100644 --- a/bundle/manifests/nexus-operator.clusterserviceversion.yaml +++ b/bundle/manifests/nexus-operator.clusterserviceversion.yaml @@ -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.5.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: 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 5d24e77a..0bca6525 100644 --- a/controllers/nexus/resource/validation/validation.go +++ b/controllers/nexus/resource/validation/validation.go @@ -80,21 +80,7 @@ func (v *Validator) SetDefaultsAndValidate(nexus *v1alpha1.Nexus) (*v1alpha1.Nex } func (v *Validator) validate(nexus *v1alpha1.Nexus) error { - validators := []func(*v1alpha1.Nexus) error{v.validateDeployment, v.validateNetworking} - for _, v := range validators { - if err := v(nexus); err != nil { - return err - } - } - return nil -} - -func (v *Validator) validateDeployment(nexus *v1alpha1.Nexus) error { - if nexus.Spec.Replicas > 1 { - v.log.Warn("Nexus server only supports 1 replica.", "Desired Replicas", nexus.Spec.Replicas) - nexus.Spec.Replicas = ensureMaximum(nexus.Spec.Replicas, 1) - } - return nil + return v.validateNetworking(nexus) } func (v *Validator) validateNetworking(nexus *v1alpha1.Nexus) error { @@ -147,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 diff --git a/nexus-operator.yaml b/nexus-operator.yaml index b2c4a71f..6b409db9 100644 --- a/nexus-operator.yaml +++ b/nexus-operator.yaml @@ -598,6 +598,16 @@ spec: control-plane: controller-manager spec: containers: + - args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=10 + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https - args: - --metrics-addr=127.0.0.1:8080 - --enable-leader-election @@ -609,16 +619,6 @@ spec: requests: cpu: 100m memory: 20Mi - - args: - - --secure-listen-address=0.0.0.0:8443 - - --upstream=http://127.0.0.1:8080/ - - --logtostderr=true - - --v=10 - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 - name: kube-rbac-proxy - ports: - - containerPort: 8443 - name: https terminationGracePeriodSeconds: 10 --- apiVersion: monitoring.coreos.com/v1