Skip to content

Commit

Permalink
Set CF_INSTANCE_INDEX env variable with downward API
Browse files Browse the repository at this point in the history
  • Loading branch information
pbusko committed Sep 18, 2024
1 parent 6412fb3 commit 67a76aa
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 321 deletions.
8 changes: 0 additions & 8 deletions controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import (
jobtaskrunnercontrollers "code.cloudfoundry.org/korifi/job-task-runner/controllers"
"code.cloudfoundry.org/korifi/kpack-image-builder/controllers"
kpackimagebuilderfinalizer "code.cloudfoundry.org/korifi/kpack-image-builder/controllers/webhooks/finalizer"
statesetfulrunnerv1 "code.cloudfoundry.org/korifi/statefulset-runner/api/v1"
statefulsetcontrollers "code.cloudfoundry.org/korifi/statefulset-runner/controllers"
"code.cloudfoundry.org/korifi/tools"
"code.cloudfoundry.org/korifi/tools/image"
Expand Down Expand Up @@ -556,13 +555,6 @@ func main() {
os.Exit(1)
}

if controllerConfig.IncludeStatefulsetRunner {
if err = statesetfulrunnerv1.NewSTSPodDefaulter().SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Pod")
os.Exit(1)
}
}

if controllerConfig.IncludeKpackImageBuilder {
kpackimagebuilderfinalizer.NewKpackImageBuilderFinalizerWebhook().SetupWebhookWithManager(mgr)
}
Expand Down
30 changes: 0 additions & 30 deletions helm/korifi/statefulset-runner/manifests.yaml

This file was deleted.

12 changes: 1 addition & 11 deletions statefulset-runner/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,12 @@ help: ## Display this help.
export GOBIN = $(shell pwd)/bin
export PATH := $(shell pwd)/bin:$(PATH)

webhooks-file = ../helm/korifi/statefulset-runner/manifests.yaml
.PHONY: manifests
manifests: bin/controller-gen bin/yq
controller-gen \
paths="./..." \
rbac:roleName=korifi-statefulset-runner-appworkload-manager-role \
webhook \
output:rbac:artifacts:config=../helm/korifi/statefulset-runner \
output:webhook:artifacts:config=../helm/korifi/statefulset-runner

yq -i 'with(.metadata; .annotations["cert-manager.io/inject-ca-from"]="{{ .Release.Namespace }}/korifi-controllers-serving-cert")' $(webhooks-file)
yq -i 'with(.metadata; .name="korifi-statefulset-runner-" + .name)' $(webhooks-file)
yq -i 'with(.webhooks[]; .clientConfig.service.namespace="{{ .Release.Namespace }}")' $(webhooks-file)
yq -i 'with(.webhooks[]; .clientConfig.service.name="korifi-controllers-" + .clientConfig.service.name)' $(webhooks-file)
yq -i 'with(.webhooks[]; .objectSelector.matchLabels["korifi.cloudfoundry.org/add-stsr-index"]="true")' $(webhooks-file)

output:rbac:artifacts:config=../helm/korifi/statefulset-runner

.PHONY: generate
generate: bin/controller-gen
Expand Down
94 changes: 0 additions & 94 deletions statefulset-runner/api/v1/pod_webhook.go

This file was deleted.

75 changes: 0 additions & 75 deletions statefulset-runner/api/v1/pod_webhook_test.go

This file was deleted.

86 changes: 0 additions & 86 deletions statefulset-runner/api/v1/webhook_suite_test.go

This file was deleted.

Empty file.
11 changes: 5 additions & 6 deletions statefulset-runner/controllers/appworkload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ const (
AnnotationAppID = "korifi.cloudfoundry.org/application-id"
AnnotationProcessGUID = "korifi.cloudfoundry.org/process-guid"

LabelGUID = "korifi.cloudfoundry.org/guid"
LabelVersion = "korifi.cloudfoundry.org/version"
LabelAppGUID = "korifi.cloudfoundry.org/app-guid"
LabelAppWorkloadGUID = "korifi.cloudfoundry.org/appworkload-guid"
LabelProcessType = "korifi.cloudfoundry.org/process-type"
LabelStatefulSetRunnerIndex = "korifi.cloudfoundry.org/add-stsr-index"
LabelGUID = "korifi.cloudfoundry.org/guid"
LabelVersion = "korifi.cloudfoundry.org/version"
LabelAppGUID = "korifi.cloudfoundry.org/app-guid"
LabelAppWorkloadGUID = "korifi.cloudfoundry.org/appworkload-guid"
LabelProcessType = "korifi.cloudfoundry.org/process-type"

ApplicationContainerName = "application"
AppWorkloadReconcilerName = "statefulset-runner"
Expand Down
19 changes: 13 additions & 6 deletions statefulset-runner/controllers/appworkload_to_stset.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ func (r *AppWorkloadToStatefulsetConverter) Convert(appWorkload *korifiv1alpha1.
},
},
},
{
Name: EnvCFInstanceIndex,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.labels['apps.kubernetes.io/pod-index']",
},
},
},
{
Name: EnvCFInstanceIP,
ValueFrom: &corev1.EnvVarSource{
Expand Down Expand Up @@ -178,12 +186,11 @@ func (r *AppWorkloadToStatefulsetConverter) Convert(appWorkload *korifiv1alpha1.
}

labels := map[string]string{
LabelGUID: appWorkload.Spec.GUID,
LabelProcessType: appWorkload.Spec.ProcessType,
LabelVersion: appWorkload.Spec.Version,
LabelAppGUID: appWorkload.Spec.AppGUID,
LabelAppWorkloadGUID: appWorkload.Name,
LabelStatefulSetRunnerIndex: "true",
LabelGUID: appWorkload.Spec.GUID,
LabelProcessType: appWorkload.Spec.ProcessType,
LabelVersion: appWorkload.Spec.Version,
LabelAppGUID: appWorkload.Spec.AppGUID,
LabelAppWorkloadGUID: appWorkload.Name,
}

statefulSet.Spec.Template.Labels = labels
Expand Down
Loading

0 comments on commit 67a76aa

Please sign in to comment.