Skip to content

Commit

Permalink
Merge pull request #74 from hyperspike/image-update
Browse files Browse the repository at this point in the history
Support updating sts images when config changes
  • Loading branch information
dmolik authored Sep 27, 2024
2 parents 1d9ec38 + 7019190 commit 2bdd15e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform

.PHONY: build-installer
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > dist/install.yaml
$Qmkdir -p dist
$Qcd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$Q$(KUSTOMIZE) build config/default > dist/install.yaml

##@ Deployment

Expand Down
4 changes: 2 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: ghcr.io/hyperspike/valkey-operator
newTag: v0.0.19
newName: localhost:5000/controller
newTag: "1"
23 changes: 23 additions & 0 deletions internal/controller/valkey_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,29 @@ export VALKEY_CLUSTER_ANNOUNCE_HOSTNAME="${POD_NAME}.%s"
}
r.Recorder.Event(valkey, "Normal", "Updated", fmt.Sprintf("StatefulSet %s/%s is updated (exporter)", valkey.Namespace, valkey.Name))
}
if sts.Spec.Template.Spec.Containers[0].Image != image {
sts.Spec.Template.Spec.Containers[0].Image = image
if valkey.Spec.VolumePermissions {
sts.Spec.Template.Spec.InitContainers[0].Image = image
}
if err := r.Update(ctx, sts); err != nil {
logger.Error(err, "failed to update statefulset image", "valkey", valkey.Name, "namespace", valkey.Namespace)
return err
}
r.Recorder.Event(valkey, "Normal", "Updated", fmt.Sprintf("StatefulSet %s/%s is updated (image)", valkey.Namespace, valkey.Name))
}
exporterImage := r.GlobalConfig.ExporterImage
if valkey.Spec.ExporterImage != "" {
exporterImage = valkey.Spec.ExporterImage
}
if valkey.Spec.Prometheus && sts.Spec.Template.Spec.Containers[1].Image != exporterImage {
sts.Spec.Template.Spec.Containers[1].Image = exporterImage
if err := r.Update(ctx, sts); err != nil {
logger.Error(err, "failed to update statefulset exporter image", "valkey", valkey.Name, "namespace", valkey.Namespace)
return err
}
r.Recorder.Event(valkey, "Normal", "Updated", fmt.Sprintf("StatefulSet %s/%s is updated (exporter image)", valkey.Namespace, valkey.Name))
}

return nil
}
Expand Down

0 comments on commit 2bdd15e

Please sign in to comment.