From 66aace4ab14ae24348ce26678194561219e8f682 Mon Sep 17 00:00:00 2001 From: Jestin Woods Date: Fri, 17 Nov 2023 14:52:53 -0800 Subject: [PATCH] refactor --- controllers/humiobootstraptoken_defaults.go | 9 +++++---- controllers/humiobootstraptoken_pods.go | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/controllers/humiobootstraptoken_defaults.go b/controllers/humiobootstraptoken_defaults.go index 2b3cfbb24..cf201cff9 100644 --- a/controllers/humiobootstraptoken_defaults.go +++ b/controllers/humiobootstraptoken_defaults.go @@ -13,7 +13,8 @@ import ( ) const ( - BootstrapTokenSuffix = "bootstrap-token" + bootstrapTokenSuffix = "bootstrap-token" + bootstrapTokenPodNameSuffix = "bootstrap-token-onetime" ) type HumioBootstrapTokenConfig struct { @@ -29,7 +30,7 @@ func (b *HumioBootstrapTokenConfig) bootstrapTokenName() string { if b.BootstrapToken.Spec.TokenSecret.SecretKeyRef != nil { return b.BootstrapToken.Spec.TokenSecret.SecretKeyRef.Name } - return fmt.Sprintf("%s-%s", b.BootstrapToken.Name, BootstrapTokenSuffix) + return fmt.Sprintf("%s-%s", b.BootstrapToken.Name, bootstrapTokenSuffix) } func (b *HumioBootstrapTokenConfig) create() (bool, error) { @@ -100,8 +101,8 @@ func (b *HumioBootstrapTokenConfig) resources() corev1.ResourceRequirements { } } -func (b *HumioBootstrapTokenConfig) name() string { - return b.BootstrapToken.Name +func (b *HumioBootstrapTokenConfig) podName() string { + return fmt.Sprintf("%s-%s", b.BootstrapToken.Name, bootstrapTokenPodNameSuffix) } func (b *HumioBootstrapTokenConfig) namespace() string { diff --git a/controllers/humiobootstraptoken_pods.go b/controllers/humiobootstraptoken_pods.go index de0d24faf..f963bbb87 100644 --- a/controllers/humiobootstraptoken_pods.go +++ b/controllers/humiobootstraptoken_pods.go @@ -1,8 +1,6 @@ package controllers import ( - "fmt" - "github.com/humio/humio-operator/pkg/helpers" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -12,7 +10,7 @@ func ConstructBootstrapPod(bootstrapConfig *HumioBootstrapTokenConfig) *corev1.P userID := int64(65534) return &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-bootstrap-token-onetime", bootstrapConfig.name()), + Name: bootstrapConfig.podName(), Namespace: bootstrapConfig.namespace(), }, Spec: corev1.PodSpec{