Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #191 - Changing deployment strategy to recreate and setting replicas to max 1 #192

Merged
merged 4 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.0
VERSION ?= 0.5.0
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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).
6 changes: 2 additions & 4 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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.
- #191 - Pod fails to start after modifying the Nexus resource
30 changes: 15 additions & 15 deletions bundle/manifests/nexus-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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
operators.operatorframework.io/project_layout: go.kubebuilder.io/v2
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: {}
Expand Down Expand Up @@ -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/
Expand All @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/m88i/nexus-operator
newTag: 0.4.0
newTag: 0.5.0
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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
operators.operatorframework.io/project_layout: go.kubebuilder.io/v2
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: {}
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions controllers/nexus/resource/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions controllers/nexus/resource/validation/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (
probeDefaultPeriodSeconds = int32(10)
probeDefaultSuccessThreshold = int32(1)
probeDefaultFailureThreshold = int32(3)

maxReplicas = int32(1)
)

var (
Expand Down
15 changes: 15 additions & 0 deletions controllers/nexus/resource/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions controllers/nexus/resource/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions nexus-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
Expand Down