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 2 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 to the operator (see #61).
ricardozanini marked this conversation as resolved.
Show resolved Hide resolved
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
10 changes: 5 additions & 5 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 @@ -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:
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
23 changes: 22 additions & 1 deletion controllers/nexus/resource/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
ricardozanini marked this conversation as resolved.
Show resolved Hide resolved
nexus.Spec.Replicas = ensureMaximum(nexus.Spec.Replicas, 1)
}
ricardozanini marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

func (v *Validator) validateNetworking(nexus *v1alpha1.Nexus) error {
Expand Down Expand Up @@ -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
}
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
2 changes: 1 addition & 1 deletion nexus-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down