Skip to content

Commit

Permalink
Bugfix31 (#253)
Browse files Browse the repository at this point in the history
* Taking init image update in sts, out of migration check.

* Bumped apimachinery version

* Update 3.1.0 tag in the repo

---------

Co-authored-by: Tanmay Jain <[email protected]>
  • Loading branch information
abhishekdwivedi3060 and tanmayja authored Oct 14, 2023
1 parent 8445508 commit d13f63a
Show file tree
Hide file tree
Showing 20 changed files with 1,225 additions and 301 deletions.
4 changes: 0 additions & 4 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# Helm-chart related ignore rules should be added directly in the Snyk UI

ignore:
SNYK-RHEL8-OPENSSLLIBS-3315644:
- '*':
reason: fix not available
expires: 2023-04-18T11:38:28.614Z
SNYK-CC-K8S-1:
- 'config/samples/storage/aerospike_local_volume_provisioner.yaml > *':
reason: Third-party (Local Static Provisioner) manifest file
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} GO111MODULE=on go
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest

# Version of Operator (build arg)
ARG VERSION="3.0.0"
ARG VERSION="3.1.0"

# User to run container as
ARG USER="root"
Expand Down
8 changes: 4 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ pipeline {
sh "set +x; ./snyk-linux auth \$(cat ${env.WORKSPACE}/../../aerospike-kubernetes-operator-resources/third-party-credentials/snyk); set -x"

// Scan the dependencies
sh "./snyk-linux test --severity-threshold=high"
sh "./snyk-linux test --severity-threshold=high --fail-on=all"

// Scan the operator images
sh "./snyk-linux container test ${OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME} --severity-threshold=high --file=Dockerfile --policy-path=.snyk"
sh "./snyk-linux container test ${OPERATOR_BUNDLE_IMAGE_CANDIDATE_NAME} --severity-threshold=high --file=Dockerfile --policy-path=.snyk"
sh "./snyk-linux container test ${OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME} --severity-threshold=high --file=Dockerfile --policy-path=.snyk --fail-on=all"
sh "./snyk-linux container test ${OPERATOR_BUNDLE_IMAGE_CANDIDATE_NAME} --severity-threshold=high --file=Dockerfile --policy-path=.snyk --fail-on=all"
}
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ boolean isNightly() {
}

String getVersion() {
def prefix = "3.0.0"
def prefix = "3.1.0"
def candidateName = ""
if(isNightly()) {
def timestamp = new Date().format("yyyy-MM-dd")
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OPENSHIFT_VERSION="v4.9"
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
# TODO: Version must be pulled from git tags
VERSION ?= 3.0.0
VERSION ?= 3.1.0

# Platforms supported
PLATFORMS ?= linux/amd64,linux/arm64
Expand Down Expand Up @@ -254,7 +254,7 @@ submodules: ## Pull and update git submodules recursively

# Generate bundle manifests and metadata, then validate generated files.
# For OpenShift bundles run
# CHANNELS=stable DEFAULT_CHANNEL=stable OPENSHIFT_VERSION=v4.6 IMG=docker.io/aerospike/aerospike-kubernetes-operator-nightly:3.0.0 make bundle
# CHANNELS=stable DEFAULT_CHANNEL=stable OPENSHIFT_VERSION=v4.6 IMG=docker.io/aerospike/aerospike-kubernetes-operator-nightly:3.1.0 make bundle
.PHONY: bundle
bundle: manifests kustomize
rm -rf $(ROOT_DIR)/bundle.Dockerfile $(BUNDLE_DIR)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Run the following command with the appropriate name and version for the operator

```sh
IMAGE_TAG_BASE=aerospike/aerospike-kubernetes-operator-nightly
VERSION=3.0.0
VERSION=3.1.0
make docker-buildx IMG=${IMAGE_TAG_BASE}:${VERSION} PLATFORMS=linux/amd64
```
**Note**: Change `PLATFORMS` var as per host machine or remove it to build multi-arch image
Expand Down Expand Up @@ -94,7 +94,7 @@ Set up the environment with image names.
```shell
export ACCOUNT=aerospike
export IMAGE_TAG_BASE=${ACCOUNT}/aerospike-kubernetes-operator
export VERSION=3.0.0
export VERSION=3.1.0
export IMG=docker.io/${IMAGE_TAG_BASE}-nightly:${VERSION}
export BUNDLE_IMG=docker.io/${IMAGE_TAG_BASE}-bundle-nightly:${VERSION}
export CATALOG_IMG=docker.io/${IMAGE_TAG_BASE}-catalog-nightly:${VERSION}
Expand Down
2 changes: 1 addition & 1 deletion api/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
AerospikeInitContainerRegistryEnvVar = "AEROSPIKE_KUBERNETES_INIT_REGISTRY"
AerospikeInitContainerDefaultRegistry = "docker.io"
AerospikeInitContainerDefaultRegistryNamespace = "aerospike"
AerospikeInitContainerDefaultRepoAndTag = "aerospike-kubernetes-init:2.1.0-dev2"
AerospikeInitContainerDefaultRepoAndTag = "aerospike-kubernetes-init:2.1.0"
AerospikeAppLabel = "app"
AerospikeCustomResourceLabel = "aerospike.com/cr"
AerospikeRackIDLabel = "aerospike.com/rack-id"
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ configMapGenerator:
images:
- name: controller
newName: docker.io/aerospike/aerospike-kubernetes-operator-nightly
newTag: 3.0.0
newTag: 3.1.0
9 changes: 9 additions & 0 deletions controllers/rack.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ func (r *SingleClusterReconciler) reconcileRack(
}
}

if err := r.updateAerospikeInitContainerImage(found); err != nil {
r.Log.Error(
err, "Failed to update Aerospike Init container", "stsName",
found.Name,
)

return reconcileError(err)
}

found, res = r.upgradeOrRollingRestartRack(found, rackState, ignorablePods, failedPods)
if !res.isSuccess {
return res
Expand Down
8 changes: 0 additions & 8 deletions controllers/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,6 @@ func (r *SingleClusterReconciler) migrateAerospikeCluster(ctx context.Context, h
r.Log.Error(err, "Problem patching Initialised volumes")
return err
}

if err := r.updateAerospikeInitContainerImage(); err != nil {
r.Log.Error(
err, "Failed to update Aerospike Init container",
)

return err
}
}

if err := r.AddAPIVersionLabel(ctx); err != nil {
Expand Down
43 changes: 28 additions & 15 deletions controllers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func getSTSHeadLessSvcName(aeroCluster *asdbv1.AerospikeCluster) string {
}

func (r *SingleClusterReconciler) createOrUpdateSTSHeadlessSvc() error {
r.Log.Info("Create or Update headless service for statefulSet")

serviceName := getSTSHeadLessSvcName(r.aeroCluster)
service := &corev1.Service{}

Expand All @@ -37,6 +35,8 @@ func (r *SingleClusterReconciler) createOrUpdateSTSHeadlessSvc() error {
return err
}

r.Log.Info("Creating headless service for statefulSet")

ls := utils.LabelsForAerospikeCluster(r.aeroCluster.Name)
service = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -77,11 +77,15 @@ func (r *SingleClusterReconciler) createOrUpdateSTSHeadlessSvc() error {
)
}

r.Log.Info("Created new headless service")
r.Log.Info("Created new headless service",
"name", utils.NamespacedName(service.Namespace, service.Name))

return nil
}

r.Log.Info("Headless service already exist, checking for update",
"name", utils.NamespacedName(service.Namespace, service.Name))

return r.updateServicePorts(service)
}

Expand Down Expand Up @@ -142,19 +146,22 @@ func (r *SingleClusterReconciler) createOrUpdateSTSLoadBalancerSvc() error {
return nErr
}

r.Log.Info(
"Created new LoadBalancer service.", "serviceName",
service.GetName(),
)
r.Log.Info("Created new LoadBalancer service",
"name", service.GetName())

return nil
}

return err
}

r.Log.Info("LoadBalancer service already exist for cluster, checking for update",
"name", utils.NamespacedName(service.Namespace, service.Name))

if len(service.Spec.Ports) == 1 && service.Spec.Ports[0].Port == servicePort.Port &&
service.Spec.Ports[0].TargetPort == servicePort.TargetPort {
r.Log.Info("LoadBalancer service update not required, skipping",
"name", utils.NamespacedName(service.Namespace, service.Name))
return nil
}

Expand All @@ -169,10 +176,8 @@ func (r *SingleClusterReconciler) createOrUpdateSTSLoadBalancerSvc() error {
)
}

r.Log.Info(
"LoadBalancer Service already exist for cluster. Updated existing service",
"name", utils.NamespacedName(service.Namespace, service.Name),
)
r.Log.Info("LoadBalancer service updated",
"name", utils.NamespacedName(service.Namespace, service.Name))

return nil
}
Expand All @@ -190,6 +195,7 @@ func (r *SingleClusterReconciler) createOrUpdatePodService(pName, pNamespace str
return err
}

r.Log.Info("Creating new service for pod")
// NodePort will be allocated automatically
service = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -224,9 +230,15 @@ func (r *SingleClusterReconciler) createOrUpdatePodService(pName, pNamespace str
)
}

r.Log.Info("Created new service for pod",
"name", utils.NamespacedName(service.Namespace, service.Name))

return nil
}

r.Log.Info("Service already exist, checking for update",
"name", utils.NamespacedName(service.Namespace, service.Name))

return r.updateServicePorts(service)
}

Expand Down Expand Up @@ -268,6 +280,9 @@ func (r *SingleClusterReconciler) updateServicePorts(service *corev1.Service) er
}

if reflect.DeepEqual(servicePortsMap, specPortsMap) {
r.Log.Info("Service update not required, skipping",
"name", utils.NamespacedName(service.Namespace, service.Name))

return nil
}

Expand All @@ -280,10 +295,8 @@ func (r *SingleClusterReconciler) updateServicePorts(service *corev1.Service) er
)
}

r.Log.Info(
"Service already exist. Updated existing service",
"name", utils.NamespacedName(service.Namespace, service.Name),
)
r.Log.Info("Service updated",
"name", utils.NamespacedName(service.Namespace, service.Name))

return nil
}
Expand Down
67 changes: 29 additions & 38 deletions controllers/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,53 +1090,44 @@ func (r *SingleClusterReconciler) updateContainerImages(statefulset *appsv1.Stat
updateImage(statefulset.Spec.Template.Spec.InitContainers)
}

func (r *SingleClusterReconciler) updateAerospikeInitContainerImage() error {
stsList, err := r.getClusterSTSList()
if err != nil {
return err
}
func (r *SingleClusterReconciler) updateAerospikeInitContainerImage(statefulSet *appsv1.StatefulSet) error {
for idx := range statefulSet.Spec.Template.Spec.InitContainers {
container := &statefulSet.Spec.Template.Spec.InitContainers[idx]
if container.Name != asdbv1.AerospikeInitContainerName {
continue
}

for stsIdx := range stsList.Items {
statefulSet := stsList.Items[stsIdx]
for idx := range statefulSet.Spec.Template.Spec.InitContainers {
container := &statefulSet.Spec.Template.Spec.InitContainers[idx]
if container.Name != asdbv1.AerospikeInitContainerName {
continue
}
desiredImage, err := utils.GetDesiredImage(
r.aeroCluster, container.Name,
)
if err != nil {
return err
}

desiredImage, err := utils.GetDesiredImage(
r.aeroCluster, container.Name,
if !utils.IsImageEqual(container.Image, desiredImage) {
r.Log.Info(
"Updating image in statefulset spec", "container",
container.Name, "desiredImage", desiredImage,
"currentImage",
container.Image,
)
if err != nil {
return err
}

if !utils.IsImageEqual(container.Image, desiredImage) {
r.Log.Info(
"Updating image in statefulset spec",
"statefulset", statefulSet.Name,
"container", container.Name,
"desiredImage", desiredImage,
"currentImage", container.Image,
)

statefulSet.Spec.Template.Spec.InitContainers[idx].Image = desiredImage
statefulSet.Spec.Template.Spec.InitContainers[idx].Image = desiredImage

if err := r.Client.Update(context.TODO(), &statefulSet, updateOption); err != nil {
return fmt.Errorf(
"failed to update StatefulSet %s: %v",
statefulSet.Name,
err,
)
}

r.Log.V(1).Info(
"Saved StatefulSet", "statefulSet", statefulSet,
if err := r.Client.Update(context.TODO(), statefulSet, updateOption); err != nil {
return fmt.Errorf(
"failed to update StatefulSet %s: %v",
statefulSet.Name,
err,
)
}

break
r.Log.V(1).Info(
"Saved StatefulSet", "statefulSet", *statefulSet,
)
}

break
}

return nil
Expand Down
Loading

0 comments on commit d13f63a

Please sign in to comment.