Skip to content

Commit cb4db6a

Browse files
sebrandon1openshift-cherrypick-robot
authored andcommitted
CNF-22870: Define constants for magic strings in istiocsr
Replace magic string literals with named constants: - "Kubernetes" default cluster ID → defaultClusterID - "default" Istio revision name → defaultIstioRevision - Consolidate duplicate istiodCertificateDefaultDNSName constant into istiodCertificateCommonNameFmt (both were "istiod.%s.svc") This improves readability and keeps test assertions in sync with production defaults.
1 parent 85c89c5 commit cb4db6a

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

pkg/controller/istiocsr/certificates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func updateCertificateParams(istiocsr *v1alpha1.IstioCSR, certificate *certmanag
8787
if revision == "" {
8888
continue
8989
}
90-
if revision == "default" {
91-
name := fmt.Sprintf(istiodCertificateDefaultDNSName, istiocsr.Spec.IstioCSRConfig.Istio.Namespace)
90+
if revision == defaultIstioRevision {
91+
name := fmt.Sprintf(istiodCertificateCommonNameFmt, istiocsr.Spec.IstioCSRConfig.Istio.Namespace)
9292
dnsNames = append(dnsNames, name)
9393
continue
9494
}

pkg/controller/istiocsr/constants.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,22 @@ const (
4545
// containing the image version of the istiocsr as value.
4646
istiocsrImageVersionEnvVarName = "ISTIOCSR_OPERAND_IMAGE_VERSION"
4747

48+
// defaultClusterID is the default Kubernetes cluster identifier used by istio-csr
49+
// when no custom cluster ID is configured.
50+
defaultClusterID = "Kubernetes"
51+
52+
// defaultIstioRevision is the Istio default revision name. When this revision is
53+
// specified, the DNS SAN uses the base istiod service name rather than a
54+
// revision-prefixed name.
55+
defaultIstioRevision = "default"
56+
4857
// istiocsrGRPCEndpointFmt is the format string for the istiocsr GRPC service endpoint.
4958
istiocsrGRPCEndpointFmt = "%s.%s.svc:%d"
5059

51-
// istiodCertificateCommonNameFmt is the format string for deriving the istiod certificate common name.
60+
// istiodCertificateCommonNameFmt is the format string for deriving the istiod certificate common name
61+
// and default DNS name.
5262
istiodCertificateCommonNameFmt = "istiod.%s.svc"
5363

54-
// istiodCertificateDefaultDNSName is the format string for deriving the istiod certificate default DNS name.
55-
istiodCertificateDefaultDNSName = "istiod.%s.svc"
56-
5764
// istiodCertificateRevisionBasedDNSName is the format string for deriving the istiod certificate DNS name
5865
// for each defined revision.
5966
istiodCertificateRevisionBasedDNSName = "istiod-%s.%s.svc"

pkg/controller/istiocsr/deployments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func updatePodTemplateLabels(deployment *appsv1.Deployment, resourceLabels map[s
137137
func updateArgList(deployment *appsv1.Deployment, istiocsr *v1alpha1.IstioCSR) {
138138
istiocsrConfigs := istiocsr.Spec.IstioCSRConfig
139139
// Default clusterID to "Kubernetes" if not provided.
140-
clusterID := "Kubernetes"
140+
clusterID := defaultClusterID
141141
if istiocsrConfigs.Server != nil && istiocsrConfigs.Server.ClusterID != "" {
142142
clusterID = istiocsrConfigs.Server.ClusterID
143143
}

pkg/controller/istiocsr/deployments_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ func TestUpdateArgList(t *testing.T) {
11051105
// Server config is nil, so clusterID should default
11061106
},
11071107
expectedArgs: map[string]string{
1108-
"cluster-id": "Kubernetes",
1108+
"cluster-id": defaultClusterID,
11091109
},
11101110
},
11111111
{
@@ -1116,7 +1116,7 @@ func TestUpdateArgList(t *testing.T) {
11161116
}
11171117
},
11181118
expectedArgs: map[string]string{
1119-
"cluster-id": "Kubernetes",
1119+
"cluster-id": defaultClusterID,
11201120
},
11211121
},
11221122
{

0 commit comments

Comments
 (0)