Skip to content

Commit

Permalink
chore: cleanup the legacy implicit envs (#8171)
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf authored Sep 20, 2024
1 parent 240bbf8 commit 2fb045e
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 502 deletions.
92 changes: 0 additions & 92 deletions controllers/apps/component_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,98 +1231,6 @@ var _ = Describe("Component Controller", func() {
},
},
},
{
Name: constant.KBEnvNamespace,
Value: clusterObj.Namespace,
},
{
Name: constant.KBEnvClusterName,
Value: clusterObj.Name,
},
{
Name: constant.KBEnvClusterUID,
Value: string(clusterObj.UID),
},
{
Name: constant.KBEnvClusterCompName,
Value: constant.GenerateClusterComponentName(clusterObj.Name, compName),
},
{
Name: constant.KBEnvCompName,
Value: compName,
},
{
Name: constant.KBEnvCompReplicas,
Value: "1", // default replicas
},
{
Name: constant.KBEnvPodName,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "metadata.name",
},
},
},
{
Name: constant.KBEnvPodUID,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "metadata.uid",
},
},
},
{
Name: constant.KBEnvPodIP,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "status.podIP",
},
},
},
{
Name: constant.KBEnvPodIPs,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "status.podIPs",
},
},
},
{
Name: constant.KBEnvPodFQDN,
Value: fmt.Sprintf("%s.%s-headless.%s.svc", constant.EnvPlaceHolder(constant.KBEnvPodName),
constant.GenerateClusterComponentName(clusterObj.Name, compName), constant.EnvPlaceHolder(constant.KBEnvNamespace)),
},
{
Name: constant.KBEnvNodeName,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "spec.nodeName",
},
},
},
{
Name: constant.KBEnvHostIP,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "status.hostIP",
},
},
},
{
Name: constant.KBEnvServiceAccountName,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "spec.serviceAccountName",
},
},
},
}
itsKey := types.NamespacedName{
Namespace: compObj.Namespace,
Expand Down
3 changes: 2 additions & 1 deletion controllers/apps/operations/custom/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
kbEnvCompHeadlessSVCName = "KB_COMP_HEADLESS_SVC_NAME"
kbEnvCompSVCName = "KB_COMP_SVC_NAME"
kbEnvCompSVCPortPrefix = "KB_COMP_SVC_PORT_"
kbEnvCompServiceVersion = "KB_COMP_SERVICE_VERSION"
kbEnvAccountUserName = "KB_ACCOUNT_USERNAME"
kbEnvAccountPassword = "KB_ACCOUNT_PASSWORD"
)
Expand Down Expand Up @@ -80,7 +81,7 @@ func buildComponentEnvs(reqCtx intctrlutil.RequestCtx,
return intctrlutil.NewFatalError(fmt.Sprintf(`componentDefinition "%s" is not support for this operations`, compDef.Name))
}

*env = append(*env, corev1.EnvVar{Name: constant.KBEnvCompServiceVersion, Value: compDef.Spec.ServiceVersion})
*env = append(*env, corev1.EnvVar{Name: kbEnvCompServiceVersion, Value: compDef.Spec.ServiceVersion})

buildSecretKeyRef := func(secretName, key string) *corev1.EnvVarSource {
return &corev1.EnvVarSource{
Expand Down
1 change: 0 additions & 1 deletion pkg/constant/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const (
PVLastClaimPolicyAnnotationKey = "apps.kubeblocks.io/pv-last-claim-policy"
HaltRecoveryAllowInconsistentResAnnotKey = "clusters.apps.kubeblocks.io/allow-inconsistent-resource"
KubeBlocksGenerationKey = "kubeblocks.io/generation"
ExtraEnvAnnotationKey = "kubeblocks.io/extra-env"
LastRoleSnapshotVersionAnnotationKey = "apps.kubeblocks.io/last-role-snapshot-version"
ComponentScaleInAnnotationKey = "apps.kubeblocks.io/component-scale-in" // ComponentScaleInAnnotationKey specifies whether the component is scaled in
DisableHAAnnotationKey = "kubeblocks.io/disable-ha"
Expand Down
9 changes: 0 additions & 9 deletions pkg/constant/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ const (
RBACClusterRoleName = "kubeblocks-volume-protection-pod-role"
)

// TODO: deprecated, will be removed later.
const (
KBComponentEnvCMPlaceHolder = "$(COMP_ENV_CM_NAME)"
KBToolsImagePlaceHolder = "$(KUBEBLOCKS_TOOLS_IMAGE)"
)

const (
KBServiceAccountName = "KUBEBLOCKS_SERVICEACCOUNT_NAME"
KBToolsImage = "KUBEBLOCKS_TOOLS_IMAGE"
Expand All @@ -45,7 +39,6 @@ const (
PodKind = "Pod"
JobKind = "Job"
VolumeSnapshotKind = "VolumeSnapshot"
ServiceKind = "Service"
)

// username and password are keys in created secrets for others to refer to.
Expand All @@ -69,9 +62,7 @@ const (
KubeblocksAPIConversionTypeAnnotationName = "api.kubeblocks.io/converted"
SourceAPIVersionAnnotationName = "api.kubeblocks.io/source"

SourceAPIVersion = "source"
MigratedAPIVersion = "migrated"
ReviewAPIVersion = "reviewer"
)

const InvalidContainerPort int32 = 0
Expand Down
58 changes: 5 additions & 53 deletions pkg/constant/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,68 +19,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

package constant

import (
"fmt"
)

func EnvPlaceHolder(env string) string {
return fmt.Sprintf("$(%s)", env)
}

// Global
const (
KBEnvNamespace = "KB_NAMESPACE"
)

// Cluster
const (
KBEnvClusterName = "KB_CLUSTER_NAME"
KBEnvClusterUID = "KB_CLUSTER_UID"
KBEnvClusterCompName = "KB_CLUSTER_COMP_NAME"
KBEnvClusterUIDPostfix8Deprecated = "KB_CLUSTER_UID_POSTFIX_8"
KBEnvClusterName = "KB_CLUSTER_NAME"
KBEnvClusterUID = "KB_CLUSTER_UID"
KBEnvClusterCompName = "KB_CLUSTER_COMP_NAME"
)

// Component
const (
KBEnvCompName = "KB_COMP_NAME"
KBEnvCompReplicas = "KB_COMP_REPLICAS"
KBEnvCompServiceVersion = "KB_COMP_SERVICE_VERSION"
)

// Pod
const (
KBEnvPodName = "KB_POD_NAME"
KBEnvPodUID = "KB_POD_UID"
KBEnvPodIP = "KB_POD_IP"
KBEnvPodIPs = "KB_POD_IPS"
KBEnvPodFQDN = "KB_POD_FQDN"
KBEnvPodOrdinal = "KB_POD_ORDINAL"
KBEnvPodIPDeprecated = "KB_PODIP"
KBEnvPodIPsDeprecated = "KB_PODIPS"
)

// Host
const (
KBEnvHostIP = "KB_HOST_IP"
KBEnvNodeName = "KB_NODENAME"
KBEnvHostIPDeprecated = "KB_HOSTIP"
)

// ServiceAccount
const (
KBEnvServiceAccountName = "KB_SA_NAME"
)

// TLS
const (
KBEnvTLSCertPath = "KB_TLS_CERT_PATH"
KBEnvTLSCertFile = "KB_TLS_CERT_FILE"
KBEnvTLSCAFile = "KB_TLS_CA_FILE"
KBEnvTLSKeyFile = "KB_TLS_KEY_FILE"
)

// Lorry
const (
KBEnvServiceUser = "KB_SERVICE_USER"
KBEnvServicePassword = "KB_SERVICE_PASSWORD"
KBEnvCompName = "KB_COMP_NAME"
KBEnvCompReplicas = "KB_COMP_REPLICAS"
)
4 changes: 2 additions & 2 deletions pkg/controller/component/kbagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ var _ = Describe("kb-agent", func() {

c := kbAgentContainer()
Expect(c).ShouldNot(BeNil())
Expect(c.Env).Should(HaveLen(2))
Expect(c.Env).Should(HaveLen(6))
})

It("action env", func() {
Expand All @@ -177,7 +177,7 @@ var _ = Describe("kb-agent", func() {

c := kbAgentContainer()
Expect(c).ShouldNot(BeNil())
Expect(c.Env).Should(HaveLen(4))
Expect(c.Env).Should(HaveLen(8))
Expect(reflect.DeepEqual(c.Env[0], env[0])).Should(BeTrue())
Expect(reflect.DeepEqual(c.Env[1], env[1])).Should(BeTrue())
})
Expand Down
Loading

0 comments on commit 2fb045e

Please sign in to comment.