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

chore: add podAnnotaions to varnish pods and fix yq #1

Merged
merged 4 commits into from
Apr 10, 2023
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
52 changes: 20 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
VERSION ?= local
REPO ?= cinple
PUBLISH_IMG ?= ${REPO}/varnish-operator:${VERSION}
PUBLISH_IMG ?= varnish-operator:${VERSION}
IMG ?= ${PUBLISH_IMG}-dev
VARNISH_PUBLISH_IMG ?= varnish:${VERSION}
VARNISH_IMG ?= ${VARNISH_PUBLISH_IMG}-dev
Expand Down Expand Up @@ -71,15 +71,12 @@ docker-build: test

# Tag and push the docker image
docker-tag-push:
ifndef REPO_PATH
$(error must set REPO_PATH, eg "make docker-tag-push REPO_PATH=${REPO}")
endif
ifndef PUBLISH
docker tag ${IMG} ${REPO_PATH}/${IMG}
docker push ${REPO_PATH}/${IMG}
docker tag ${IMG} ${REPO}/${IMG}
docker push ${REPO}/${IMG}
else
docker tag ${IMG} ${REPO_PATH}/${PUBLISH_IMG}
docker push ${REPO_PATH}/${PUBLISH_IMG}
docker tag ${IMG} ${REPO}/${PUBLISH_IMG}
docker push ${REPO}/${PUBLISH_IMG}
endif

varnish-controller: fmt vet
Expand All @@ -90,47 +87,38 @@ docker-build-varnish:
docker build --platform ${PLATFORM} ${ROOT_DIR} -t ${VARNISH_IMG} -f Dockerfile.varnishd

docker-tag-push-varnish:
ifndef REPO_PATH
$(error must set REPO_PATH, eg "make docker-tag-push REPO_PATH=${REPO}")
endif
ifndef PUBLISH
docker tag ${VARNISH_IMG} ${REPO_PATH}/${VARNISH_IMG}
docker push ${REPO_PATH}/${VARNISH_IMG}
docker tag ${VARNISH_IMG} ${REPO}/${VARNISH_IMG}
docker push ${REPO}/${VARNISH_IMG}
else
docker tag ${VARNISH_IMG} ${REPO_PATH}/${VARNISH_PUBLISH_IMG}
docker push ${REPO_PATH}/${VARNISH_PUBLISH_IMG}
docker tag ${VARNISH_IMG} ${REPO}/${VARNISH_PUBLISH_IMG}
docker push ${REPO}/${VARNISH_PUBLISH_IMG}
endif

# Build the docker image with varnish controller
docker-build-varnish-controller: fmt vet
docker build --platform ${PLATFORM} ${ROOT_DIR} -t ${VARNISH_CONTROLLER_IMG} -f Dockerfile.controller

docker-tag-push-varnish-controller:
ifndef REPO_PATH
$(error must set REPO_PATH, eg "make docker-tag-push REPO_PATH=${REPO}")
endif
ifndef PUBLISH
docker tag ${VARNISH_CONTROLLER_IMG} ${REPO_PATH}/${VARNISH_CONTROLLER_IMG}
docker push ${REPO_PATH}/${VARNISH_CONTROLLER_IMG}
docker tag ${VARNISH_CONTROLLER_IMG} ${REPO}/${VARNISH_CONTROLLER_IMG}
docker push ${REPO}/${VARNISH_CONTROLLER_IMG}
else
docker tag ${VARNISH_CONTROLLER_IMG} ${REPO_PATH}/${VARNISH_CONTROLLER_PUBLISH_IMG}
docker push ${REPO_PATH}/${VARNISH_CONTROLLER_PUBLISH_IMG}
docker tag ${VARNISH_CONTROLLER_IMG} ${REPO}/${VARNISH_CONTROLLER_PUBLISH_IMG}
docker push ${REPO}/${VARNISH_CONTROLLER_PUBLISH_IMG}
endif

# Build the docker image with varnish metrics exporter
docker-build-varnish-exporter:
docker build --platform ${PLATFORM} ${ROOT_DIR} -t ${VARNISH_METRICS_IMG} -f Dockerfile.exporter

docker-tag-push-varnish-exporter:
ifndef REPO_PATH
$(error must set REPO_PATH, eg "make docker-tag-push REPO_PATH=${REPO}")
endif
ifndef PUBLISH
docker tag ${VARNISH_METRICS_IMG} ${REPO_PATH}/${VARNISH_METRICS_IMG}
docker push ${REPO_PATH}/${VARNISH_METRICS_IMG}
docker tag ${VARNISH_METRICS_IMG} ${REPO}/${VARNISH_METRICS_IMG}
docker push ${REPO}/${VARNISH_METRICS_IMG}
else
docker tag ${VARNISH_METRICS_IMG} ${REPO_PATH}/${VARNISH_METRICS_PUBLISH_IMG}
docker push ${REPO_PATH}/${VARNISH_METRICS_PUBLISH_IMG}
docker tag ${VARNISH_METRICS_IMG} ${REPO}/${VARNISH_METRICS_PUBLISH_IMG}
docker push ${REPO}/${VARNISH_METRICS_PUBLISH_IMG}
endif

docker-build-pod: docker-build-varnish docker-build-varnish-exporter docker-build-varnish-controller
Expand Down Expand Up @@ -158,9 +146,9 @@ kustomize:
# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests kustomize
yq w -i config/manager/deployment.yaml 'spec.template.spec.containers(name==varnish-operator).env(name==CONTAINER_IMAGE).value' $(PUBLISH_IMG)
yq w -i config/manifests/bases/varnish-operator.clusterserviceversion.yaml 'metadata.annotations.containerImage' $(PUBLISH_IMG)
yq w -i config/manifests/bases/varnish-operator.clusterserviceversion.yaml 'metadata.annotations.createdAt' $(date +"%Y-%m-%d")
yq -i '(.spec.template.spec.containers[0].env[] | select(.name == "CONTAINER_IMAGE") | .value) = "$(PUBLISH_IMG)"' config/manager/deployment.yaml
yq -i '.metadata.annotations.containerImage = "$(PUBLISH_IMG)"' config/manifests/bases/varnish-operator.clusterserviceversion.yaml
yq -i '.metadata.annotations.createdAt = now' config/manifests/bases/varnish-operator.clusterserviceversion.yaml
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(PUBLISH_IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/varnishcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type VarnishClusterSpec struct {
Service *VarnishClusterService `json:"service,omitempty"`
PodDisruptionBudget *policyv1.PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
Affinity *v1.Affinity `json:"affinity,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
Monitoring *VarnishClusterMonitoring `json:"monitoring,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/crd/bases/caching.ibm.com_varnishclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,10 @@ spec:
additionalProperties:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
type: object
podDisruptionBudget:
description: PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.
properties:
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ The autogenerated CRD and ClusterRole will be picked up automatically.

To generate the bundle, you have to specify the version in an env var and run `make bundle`:

`# VERSION=0.27.0 make bundle`
`# VERSION=0.27.2 make bundle`

After that, a directory named by the version will be generated with the necessary manifests.

Expand Down
1 change: 1 addition & 0 deletions docs/varnish-cluster-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| `monitoring.prometheusServiceMonitor.labels ` | ServiceMonitor labels that will be used by Prometheus instance to discover this ServiceMonitor. | `optional` |
| `monitoring.prometheusServiceMonitor.namespace ` | The namespace the it should be installed to. Default to the namespace VarnishCluster is installed to | `optional` |
| `nodeSelector` | Node selector to control where the Varnish pods should be scheduled | `optional` |
| `podAnnotations ` | Pod annotations for the Varnish pods. | `optional` |
| `podDisruptionBudget ` | [Pod Disruption Budget](https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget) configuration. Can be used to tell Kubernetes how many pods are required to be up (or allowed to be down) to not cause service disruption | `optional` |
| `podDisruptionBudget.minAvailable ` | An eviction is allowed if at least `minAvailable` pods will still be available after the eviction, i.e. even in the absence of the evicted pod | `optional` |
| `podDisruptionBudget.maxUnavailable ` | An eviction is allowed if at most `maxUnavailable` pods are unavailable after the eviction, i.e. even in absence of the evicted pod. This is a mutually exclusive setting with `minAvailable` | `optional` |
Expand Down
3 changes: 2 additions & 1 deletion pkg/varnishcluster/controller/varnishcluster_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func (r *ReconcileVarnishCluster) reconcileStatefulSet(ctx context.Context, inst
VolumeClaimTemplates: pvcs,
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: varnishLabels,
Labels: varnishLabels,
Annotations: instance.Spec.PodAnnotations,
},
Spec: v1.PodSpec{
// Share a single process namespace between all of the containers in a pod.
Expand Down
20 changes: 20 additions & 0 deletions pkg/varnishcluster/controller/varnishcluster_statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
. "github.com/onsi/gomega"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -330,6 +331,25 @@ var _ = Describe("statefulset", func() {
Expect(varnishContainer.VolumeMounts).To(ContainElement(testExtraVolumeMount))
})
})

Context("when varnishcluster is created with podAnnotations enable", func() {
It("should be created with corresponding podAnnotations set", func() {
newVC := vc.DeepCopy()
podAnnotations := map[string]string{"foo": "bar"}
newVC.Spec.PodAnnotations = podAnnotations

err := k8sClient.Create(context.Background(), newVC)
Expect(err).ToNot(HaveOccurred())

sts := &apps.StatefulSet{}
Eventually(func() error {
return k8sClient.Get(context.Background(), stsName, sts)
}, time.Second*5).Should(Succeed())

Expect(sts.Spec.Template.ObjectMeta.Annotations).To(Equal(map[string]string{"foo": "bar"}))
})

})
})

func getContainerByName(spec v1.PodSpec, name string) (v1.Container, error) {
Expand Down
4 changes: 4 additions & 0 deletions varnish-operator/crds/varnishcluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ spec:
additionalProperties:
type: string
type: object
podAnnotations:
additionalProperties:
type: string
type: object
podDisruptionBudget:
description: PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.
properties:
Expand Down