Skip to content

Commit

Permalink
supply additional labels and annotations to fs-minio pods
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Sep 6, 2024
1 parent f4907f0 commit 77eaad3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 13 deletions.
34 changes: 34 additions & 0 deletions pkg/kotsutil/kots.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"k8s.io/client-go/kubernetes"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -1140,6 +1141,8 @@ type InstallationParams struct {
WithMinio bool
AppVersionLabel string
RequestedChannelSlug string
AdditionalAnnotations map[string]string
AdditionalLabels map[string]string
}

func GetInstallationParams(configMapName string) (InstallationParams, error) {
Expand All @@ -1150,6 +1153,12 @@ func GetInstallationParams(configMapName string) (InstallationParams, error) {
return autoConfig, errors.Wrap(err, "failed to get k8s clientset")
}

return GetInstallationParamsWithClientset(clientset, configMapName)
}

func GetInstallationParamsWithClientset(clientset kubernetes.Interface, configMapName string) (InstallationParams, error) {
autoConfig := InstallationParams{}

isKurl, err := kurl.IsKurl(clientset)
if err != nil {
return autoConfig, errors.Wrap(err, "failed to check if cluster is kurl")
Expand Down Expand Up @@ -1183,6 +1192,31 @@ func GetInstallationParams(configMapName string) (InstallationParams, error) {
autoConfig.EnableImageDeletion = isKurl
}

autoConfig.AdditionalAnnotations = make(map[string]string)
allAnnotations := strings.Split(kotsadmConfigMap.Data["additional-annotations"], ",")
for _, annotation := range allAnnotations {
if annotation == "" {
continue
}
parts := strings.Split(annotation, "=")
if len(parts) != 2 {
return autoConfig, errors.Errorf("invalid additional annotation %q", annotation)
}
autoConfig.AdditionalAnnotations[parts[0]] = parts[1]
}
autoConfig.AdditionalLabels = make(map[string]string)
allLabels := strings.Split(kotsadmConfigMap.Data["additional-labels"], ",")
for _, label := range allLabels {
if label == "" {
continue
}
parts := strings.Split(label, "=")
if len(parts) != 2 {
return autoConfig, errors.Errorf("invalid additional label %q", label)
}
autoConfig.AdditionalLabels[parts[0]] = parts[1]
}

return autoConfig, nil
}

Expand Down
53 changes: 40 additions & 13 deletions pkg/snapshot/filesystem_minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
kotsadmresources "github.com/replicatedhq/kots/pkg/kotsadm/resources"
kotsadmtypes "github.com/replicatedhq/kots/pkg/kotsadm/types"
kotsadmversion "github.com/replicatedhq/kots/pkg/kotsadm/version"
"github.com/replicatedhq/kots/pkg/kotsutil"
"github.com/replicatedhq/kots/pkg/kurl"
"github.com/replicatedhq/kots/pkg/logger"
kotss3 "github.com/replicatedhq/kots/pkg/s3"
Expand Down Expand Up @@ -300,6 +301,11 @@ func fileSystemMinioDeploymentResource(clientset kubernetes.Interface, secretChe
}
}

globalOptions, err := kotsutil.GetInstallationParamsWithClientset(clientset, kotsadmtypes.KotsadmConfigMap)
if err != nil {
return nil, errors.Wrap(err, "failed to get global options")
}

env := []corev1.EnvVar{
{
Name: "MINIO_UPDATE",
Expand Down Expand Up @@ -329,13 +335,28 @@ func fileSystemMinioDeploymentResource(clientset kubernetes.Interface, secretChe
},
}

podAnnotations := map[string]string{
"kots.io/fs-minio-creds-secret-checksum": secretChecksum,
}
for k, v := range globalOptions.AdditionalAnnotations {
podAnnotations[k] = v
}
podLabels := map[string]string{
"app": "kotsadm-fs-minio",
}
for k, v := range globalOptions.AdditionalLabels {
podLabels[k] = v
}

return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: FileSystemMinioDeploymentName,
Name: FileSystemMinioDeploymentName,
Labels: globalOptions.AdditionalLabels,
Annotations: globalOptions.AdditionalAnnotations,
},
Spec: appsv1.DeploymentSpec{
Replicas: pointer.Int32Ptr(1),
Expand All @@ -349,12 +370,8 @@ func fileSystemMinioDeploymentResource(clientset kubernetes.Interface, secretChe
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "kotsadm-fs-minio",
},
Annotations: map[string]string{
"kots.io/fs-minio-creds-secret-checksum": secretChecksum,
},
Labels: podLabels,
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
SecurityContext: &securityContext,
Expand Down Expand Up @@ -837,18 +854,28 @@ func fileSystemMinioConfigPod(clientset kubernetes.Interface, deployOptions File
}
}

globalOptions, err := kotsutil.GetInstallationParamsWithClientset(clientset, kotsadmtypes.KotsadmConfigMap)
if err != nil {
return nil, errors.Wrap(err, "failed to get global options")
}
podLabels := map[string]string{
"app": "kotsadm-fs-minio",
"check": podCheckTag,
}
for k, v := range globalOptions.AdditionalLabels {
podLabels[k] = v
}

pod := &corev1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Pod",
},
ObjectMeta: metav1.ObjectMeta{
Name: podName,
Namespace: deployOptions.Namespace,
Labels: map[string]string{
"app": "kotsadm-fs-minio",
"check": podCheckTag,
},
Name: podName,
Namespace: deployOptions.Namespace,
Labels: podLabels,
Annotations: globalOptions.AdditionalAnnotations,
},
Spec: corev1.PodSpec{
SecurityContext: &securityContext,
Expand Down

0 comments on commit 77eaad3

Please sign in to comment.