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

Remove usage of active cluster name #1217

Merged
merged 3 commits into from
Oct 22, 2024
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
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"--RADIX_RESERVED_DNS_ALIASES=grafana,prometheus,www"
]
},
{
{
"name": "Launch-deploy-pipeline",
"type": "go",
"request": "launch",
Expand Down Expand Up @@ -116,7 +116,6 @@
"RADIXOPERATOR_APP_ROLLING_UPDATE_MAX_SURGE": "25%",
"RADIXOPERATOR_APP_READINESS_PROBE_INITIAL_DELAY_SECONDS": "5",
"RADIXOPERATOR_APP_READINESS_PROBE_PERIOD_SECONDS": "10",
"RADIX_ACTIVE_CLUSTERNAME": "weekly-35",
"RADIX_IMAGE_BUILDER": "radix-image-builder:master-latest",
"RADIX_TEKTON_IMAGE": "radix-tekton:main-latest",
"RADIXOPERATOR_JOB_SCHEDULER": "radix-job-scheduler:main-latest",
Expand Down
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: radix-operator
version: 1.43.3
appVersion: 1.63.3
version: 1.44.0
appVersion: 1.64.0
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
11 changes: 4 additions & 7 deletions charts/radix-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ spec:
value: {{ .Values.app.rollingUpdate.maxUnavailable | quote }}
- name: RADIXOPERATOR_APP_ROLLING_UPDATE_MAX_SURGE
value: {{ .Values.app.rollingUpdate.maxSurge | quote }}
# Active cluster name
- name: RADIX_ACTIVE_CLUSTERNAME
value: {{ .Values.activeClusterName }}
# Maximum custom resources
- name: RADIX_DEPLOYMENTS_PER_ENVIRONMENT_HISTORY_LIMIT
value: {{ .Values.deploymentsPerEnvironmentHistoryLimit | quote }}
Expand Down Expand Up @@ -174,9 +171,9 @@ spec:
- name: RADIXOPERATOR_CERTIFICATE_AUTOMATION_DURATION
value: {{ .Values.ingress.certificate.automation.duration }}
- name: RADIXOPERATOR_CERTIFICATE_AUTOMATION_RENEW_BEFORE
value: {{ .Values.ingress.certificate.automation.renewBefore }}
value: {{ .Values.ingress.certificate.automation.renewBefore }}
- name: RADIX_EXTERNAL_REGISTRY_DEFAULT_AUTH_SECRET
value: {{ .Values.externalRegistryDefaultAuthSecret }}
value: {{ .Values.externalRegistryDefaultAuthSecret }}
- name: RADIXOPERATOR_ORPHANED_ENVIRONMENTS_RETENTION_PERIOD
value: {{ .Values.task.orphanedEnvironmentsRetentionPeriod }}
- name: RADIXOPERATOR_ORPHANED_ENVIRONMENTS_CLEANUP_CRON
Expand All @@ -198,7 +195,7 @@ spec:
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand All @@ -214,4 +211,4 @@ spec:
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
1 change: 0 additions & 1 deletion charts/radix-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
nameOverride: ""
fullnameOverride: ""
clusterName: xx
activeClusterName: xx
clusterActiveEgressIps: xx

registrationControllerThreads: 1
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/defaults/environment_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ const (
// RadixClusterTypeEnvironmentVariable The type of cluster dev|playground|prod. Will be equal to OperatorClusterTypeEnvironmentVariable
RadixClusterTypeEnvironmentVariable = "RADIX_CLUSTER_TYPE"

// ActiveClusternameEnvironmentVariable The name of the active cluster. If ActiveClusternameEnvironmentVariable == ClusternameEnvironmentVariable, this is the active cluster
ActiveClusternameEnvironmentVariable = "RADIX_ACTIVE_CLUSTERNAME"

// RadixCommitHashEnvironmentVariable Contains the commit id of the build
RadixCommitHashEnvironmentVariable = "RADIX_GIT_COMMIT_HASH"

Expand Down
26 changes: 2 additions & 24 deletions pkg/apis/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TeardownTest() {
_ = os.Unsetenv(defaults.OperatorRollingUpdateMaxSurge)
_ = os.Unsetenv(defaults.OperatorReadinessProbeInitialDelaySeconds)
_ = os.Unsetenv(defaults.OperatorReadinessProbePeriodSeconds)
_ = os.Unsetenv(defaults.ActiveClusternameEnvironmentVariable)
_ = os.Unsetenv(defaults.OperatorRadixJobSchedulerEnvironmentVariable)
_ = os.Unsetenv(defaults.OperatorClusterTypeEnvironmentVariable)
_ = os.Unsetenv(defaults.OperatorTenantIdEnvironmentVariable)
Expand All @@ -119,7 +118,6 @@ func TestObjectSynced_MultiComponent_ContainsAllElements(t *testing.T) {

tu, kubeclient, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
_ = os.Setenv(defaults.ActiveClusternameEnvironmentVariable, "AnotherClusterName")

t.Run("Test Suite", func(t *testing.T) {
aRadixRegistrationBuilder := utils.ARadixRegistration().WithAdGroups(adminGroups).WithAdUsers(adminUsers).WithReaderAdGroups(readerGroups).WithReaderAdUsers(readerUsers)
Expand Down Expand Up @@ -261,7 +259,7 @@ func TestObjectSynced_MultiComponent_ContainsAllElements(t *testing.T) {
assert.Equal(t, os.Getenv(defaults.OperatorDNSZoneEnvironmentVariable), getEnvVariableByNameOnDeployment(kubeclient, defaults.RadixDNSZoneEnvironmentVariable, componentNameApp, deployments))
assert.Equal(t, "AnyClusterName", getEnvVariableByNameOnDeployment(kubeclient, defaults.ClusternameEnvironmentVariable, componentNameApp, deployments))
assert.Equal(t, environment, getEnvVariableByNameOnDeployment(kubeclient, defaults.EnvironmentnameEnvironmentVariable, componentNameApp, deployments))
assert.Equal(t, "app-edcradix-test.AnyClusterName.dev.radix.equinor.com", getEnvVariableByNameOnDeployment(kubeclient, defaults.PublicEndpointEnvironmentVariable, componentNameApp, deployments))
assert.Equal(t, "app-edcradix-test.dev.radix.equinor.com", getEnvVariableByNameOnDeployment(kubeclient, defaults.PublicEndpointEnvironmentVariable, componentNameApp, deployments))
assert.Equal(t, "app-edcradix-test.AnyClusterName.dev.radix.equinor.com", getEnvVariableByNameOnDeployment(kubeclient, defaults.CanonicalEndpointEnvironmentVariable, componentNameApp, deployments))
assert.Equal(t, appName, getEnvVariableByNameOnDeployment(kubeclient, defaults.RadixAppEnvironmentVariable, componentNameApp, deployments))
assert.Equal(t, componentNameApp, getEnvVariableByNameOnDeployment(kubeclient, defaults.RadixComponentEnvironmentVariable, componentNameApp, deployments))
Expand Down Expand Up @@ -515,7 +513,6 @@ func TestObjectSynced_MultiJob_ContainsAllElements(t *testing.T) {
testScenario := utils.TernaryString(jobsExist, "Updating deployment", "Creating deployment")

tu, kubeclient, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, "AnotherClusterName")
os.Setenv(defaults.OperatorRadixJobSchedulerEnvironmentVariable, jobSchedulerImage)

t.Run("Test Suite", func(t *testing.T) {
Expand Down Expand Up @@ -798,7 +795,6 @@ func getDeploymentsForRadixJobAux(deployments []appsv1.Deployment) []appsv1.Depl
func TestObjectSynced_MultiComponent_AllClusters_ContainsAllIngresses(t *testing.T) {
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, "AnotherClusterName")

// Test
_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient, utils.ARadixDeployment().
Expand Down Expand Up @@ -945,7 +941,6 @@ func TestObjectSynced_ReadOnlyFileSystem(t *testing.T) {
func TestObjectSynced_MultiComponent_ActiveCluster_ContainsAllIngresses(t *testing.T) {
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)

// Test
_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient, utils.ARadixDeployment().
Expand Down Expand Up @@ -2145,7 +2140,6 @@ func TestObjectUpdated_WithAppAliasRemoved_AliasIngressIsCorrectlyReconciled(t *
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)
_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient, utils.ARadixDeployment().
WithAppName("any-app").
WithEnvironment("dev").
Expand Down Expand Up @@ -2450,7 +2444,6 @@ func TestObjectUpdated_WithAllExternalAliasRemoved_ExternalAliasIngressIsCorrect
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)
_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient, utils.ARadixDeployment().
WithAppName(anyAppName).
WithEnvironment(anyEnvironment).
Expand Down Expand Up @@ -2497,7 +2490,6 @@ func TestObjectUpdated_WithOneExternalAliasRemovedOrModified_AllChangesProperlyR
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)

_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient, utils.ARadixDeployment().
WithAppName(anyAppName).
Expand Down Expand Up @@ -2608,7 +2600,6 @@ func TestFixedAliasIngress_ActiveCluster(t *testing.T) {
WithPublicPort("http"))

// Current cluster is active cluster
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)
_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient, radixDeployBuilder)
require.NoError(t, err)
ingresses, _ := client.NetworkingV1().Ingresses(envNamespace).List(context.Background(), metav1.ListOptions{})
Expand All @@ -2619,7 +2610,6 @@ func TestFixedAliasIngress_ActiveCluster(t *testing.T) {
assert.True(t, strings.Contains(defaultIngress.Spec.Rules[0].Host, testClusterName))

// Current cluster is not active cluster
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, "newClusterName")
_, err = ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient, radixDeployBuilder)
require.NoError(t, err)
ingresses, _ = client.NetworkingV1().Ingresses(envNamespace).List(context.Background(), metav1.ListOptions{})
Expand Down Expand Up @@ -3743,8 +3733,7 @@ func Test_JobScheduler_ObjectsGarbageCollected(t *testing.T) {
func Test_IngressAnnotations_Called(t *testing.T) {
_, kubeclient, kubeUtil, radixclient, _, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)
defer os.Unsetenv(defaults.ActiveClusternameEnvironmentVariable)

rr := utils.NewRegistrationBuilder().WithName("app").BuildRR()
rd := utils.NewDeploymentBuilder().WithAppName("app").WithEnvironment("dev").WithComponent(utils.NewDeployComponentBuilder().WithName("comp").WithPublicPort("http").WithDNSAppAlias(true)).BuildRD()
_, err := radixclient.RadixV1().RadixRegistrations().Create(context.Background(), rr, metav1.CreateOptions{})
Expand Down Expand Up @@ -3855,8 +3844,6 @@ func Test_ComponentSynced_VolumeAndMounts(t *testing.T) {
appName, environment, compName := "app", "dev", "comp"
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)

_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient,
utils.NewDeploymentBuilder().
Expand Down Expand Up @@ -3890,8 +3877,6 @@ func Test_JobSynced_VolumeAndMounts(t *testing.T) {
appName, environment, jobName := "app", "dev", "job"
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)

_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient,
utils.NewDeploymentBuilder().
Expand Down Expand Up @@ -3926,8 +3911,6 @@ func Test_ComponentSynced_SecretRefs(t *testing.T) {
appName, environment, compName := "app", "dev", "comp"
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)

_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient,
utils.NewDeploymentBuilder().
Expand Down Expand Up @@ -3966,8 +3949,6 @@ func Test_JobSynced_SecretRefs(t *testing.T) {
appName, environment, jobName := "app", "dev", "job"
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)

_, err := ApplyDeploymentWithSync(tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, certClient,
utils.NewDeploymentBuilder().
Expand Down Expand Up @@ -4009,8 +3990,6 @@ func Test_RestartJobManager_RestartsAuxDeployment(t *testing.T) {
appName, environment, jobName := "app", "dev", "job"
tu, client, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
defer TeardownTest()
// Setup
os.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)

applicationBuilder := utils.NewRadixApplicationBuilder().WithAppName(appName).WithRadixRegistration(utils.NewRegistrationBuilder().WithName(appName))
jobComponentBuilder := utils.NewDeployJobComponentBuilder().WithName(jobName)
Expand Down Expand Up @@ -4128,7 +4107,6 @@ func Test_ExternalDNS_Legacy_ResourcesMigrated(t *testing.T) {
ns := utils.GetEnvironmentNamespace(appName, envName)

tu, kubeclient, kubeUtil, radixclient, kedaClient, prometheusclient, _, certClient := SetupTest(t)
t.Setenv(defaults.ActiveClusternameEnvironmentVariable, testClusterName)
defer TeardownTest()

// Setup legacy secrets
Expand Down
7 changes: 1 addition & 6 deletions pkg/apis/deployment/environmentvariables.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,7 @@ func appendDefaultEnvVars(ctx context.Context, envVars []corev1.EnvVar, envVarsS
isPortPublic := deployComponent.GetPublicPort() != "" || deployComponent.IsPublic()
if isPortPublic {
canonicalHostName := getHostName(deployComponent.GetName(), namespace, clusterName, dnsZone)
publicHostName := ""
if isActiveCluster(clusterName) {
publicHostName = getActiveClusterHostName(deployComponent.GetName(), namespace)
} else {
publicHostName = canonicalHostName
}
publicHostName := getActiveClusterHostName(deployComponent.GetName(), namespace)
envVarSet.Add(defaults.PublicEndpointEnvironmentVariable, publicHostName)
envVarSet.Add(defaults.CanonicalEndpointEnvironmentVariable, canonicalHostName)
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/deployment/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,3 @@ func getPublicPortForComponent(deployComponent radixv1.RadixCommonDeployComponen

return 0
}

func isActiveCluster(clustername string) bool {
activeClustername := os.Getenv(defaults.ActiveClusternameEnvironmentVariable)
return strings.EqualFold(clustername, activeClustername)
}
1 change: 0 additions & 1 deletion pkg/apis/deployment/secretrefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func teardownSecretRefsTest() {
os.Unsetenv(defaults.OperatorRollingUpdateMaxSurge)
os.Unsetenv(defaults.OperatorReadinessProbeInitialDelaySeconds)
os.Unsetenv(defaults.OperatorReadinessProbePeriodSeconds)
os.Unsetenv(defaults.ActiveClusternameEnvironmentVariable)
os.Unsetenv(defaults.OperatorRadixJobSchedulerEnvironmentVariable)
os.Unsetenv(defaults.OperatorClusterTypeEnvironmentVariable)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/deployment/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func teardownSecretsTest() {
_ = os.Unsetenv(defaults.OperatorRollingUpdateMaxSurge)
_ = os.Unsetenv(defaults.OperatorReadinessProbeInitialDelaySeconds)
_ = os.Unsetenv(defaults.OperatorReadinessProbePeriodSeconds)
_ = os.Unsetenv(defaults.ActiveClusternameEnvironmentVariable)
_ = os.Unsetenv(defaults.OperatorRadixJobSchedulerEnvironmentVariable)
_ = os.Unsetenv(defaults.OperatorClusterTypeEnvironmentVariable)
}
Expand Down
3 changes: 0 additions & 3 deletions radix-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type Options struct {
alertControllerThreads int
kubeClientRateLimitBurst int
kubeClientRateLimitQPS float32
activeClusterNameEnvVar string
}

type App struct {
Expand Down Expand Up @@ -93,7 +92,6 @@ func main() {
if err != nil {
log.Fatal().Err(err).Msg("Failed to initialize app")
}
log.Ctx(ctx).Info().Msgf("Active cluster name: %v", app.opts.activeClusterNameEnvVar)

err = app.Run(ctx)
if err != nil {
Expand Down Expand Up @@ -233,7 +231,6 @@ func getInitParams() (Options, error) {
alertControllerThreads: alertControllerThreads,
kubeClientRateLimitBurst: kubeClientRateLimitBurst,
kubeClientRateLimitQPS: kubeClientRateLimitQPS,
activeClusterNameEnvVar: os.Getenv(defaults.ActiveClusternameEnvironmentVariable),
}, stderrors.Join(regErr, appErr, envErr, depErr, jobErr, aleErr, burstErr, qpsErr)
}

Expand Down
Loading