diff --git a/admiral/cmd/admiral/cmd/root.go b/admiral/cmd/admiral/cmd/root.go index 0dcff841..1e925405 100644 --- a/admiral/cmd/admiral/cmd/root.go +++ b/admiral/cmd/admiral/cmd/root.go @@ -4,16 +4,15 @@ import ( "context" "flag" "fmt" - "os" - "os/signal" - "syscall" - "time" - "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/routes" "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/server" "github.com/istio-ecosystem/admiral/admiral/pkg/clusters" "github.com/istio-ecosystem/admiral/admiral/pkg/controller/common" log "github.com/sirupsen/logrus" + "os" + "os/signal" + "syscall" + "time" "github.com/spf13/cobra" ) @@ -104,8 +103,6 @@ func GetRootCmd(args []string) *cobra.Command { "The label value, on a namespace, which tells Istio to perform sidecar injection") rootCmd.PersistentFlags().StringVar(¶ms.HostnameSuffix, "hostname_suffix", "global", "The hostname suffix to customize the cname generated by admiral. Default suffix value will be \"global\"") - rootCmd.PersistentFlags().StringVar(¶ms.PreviewHostnamePrefix, "preview_hostname_prefix", "preview", - "The hostname prefix to customize the cname generated by admiral for bluegreen rollout preview service. Default suffix value will be \"preview\"") rootCmd.PersistentFlags().StringVar(¶ms.LabelSet.WorkloadIdentityKey, "workload_identity_key", "identity", "The workload identity key, on deployment which holds identity value used to generate cname by admiral. Default label key will be \"identity\" Admiral will look for a label with this key. If present, that will be used. If not, it will try an annotation (for use cases where an identity is longer than 63 chars)") rootCmd.PersistentFlags().StringVar(¶ms.LabelSet.GlobalTrafficDeploymentLabel, "globaltraffic_deployment_label", "identity", diff --git a/admiral/pkg/clusters/serviceentry.go b/admiral/pkg/clusters/serviceentry.go index 93e79054..c977e3cf 100644 --- a/admiral/pkg/clusters/serviceentry.go +++ b/admiral/pkg/clusters/serviceentry.go @@ -159,7 +159,7 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s activeServiceName := sourceRollouts[sourceCluster].Spec.Strategy.BlueGreen.ActiveService previewServiceName := sourceRollouts[sourceCluster].Spec.Strategy.BlueGreen.PreviewService oldPorts := ep.Ports - if previewService, ok := weightedServices[previewServiceName]; strings.HasPrefix(key, common.GetPreviewHostnamePrefix()+common.Sep) && ok { + if previewService, ok := weightedServices[previewServiceName]; strings.HasPrefix(key, common.BlueGreenRolloutPreviewPrefix+common.Sep) && ok { previewServiceInstance := previewService.Service localFqdn := previewServiceInstance.Name + common.Sep + previewServiceInstance.Namespace + common.DotLocalDomainSuffix cnames[localFqdn] = "1" @@ -603,7 +603,7 @@ func createServiceEntryForRollout(event admiral.EventType, rc *RemoteController, if destRollout.Spec.Strategy.BlueGreen != nil && destRollout.Spec.Strategy.BlueGreen.PreviewService != "" { rolloutServices := getServiceForRollout(rc, destRollout) if _, ok := rolloutServices[destRollout.Spec.Strategy.BlueGreen.PreviewService]; ok { - previewGlobalFqdn := common.GetPreviewHostnamePrefix() + common.Sep + common.GetCnameForRollout(destRollout, workloadIdentityKey, common.GetHostnameSuffix()) + previewGlobalFqdn := common.BlueGreenRolloutPreviewPrefix + common.Sep + common.GetCnameForRollout(destRollout, workloadIdentityKey, common.GetHostnameSuffix()) previewAddress := getUniqueAddress(admiralCache, previewGlobalFqdn) if len(previewGlobalFqdn) != 0 && len(previewAddress) != 0 { generateServiceEntry(event, admiralCache, meshPorts, previewGlobalFqdn, rc, serviceEntries, previewAddress, san) diff --git a/admiral/pkg/clusters/serviceentry_test.go b/admiral/pkg/clusters/serviceentry_test.go index 1922bfe9..cd7ace3d 100644 --- a/admiral/pkg/clusters/serviceentry_test.go +++ b/admiral/pkg/clusters/serviceentry_test.go @@ -1006,7 +1006,6 @@ func TestCreateServiceEntryForBlueGreenRolloutsUsecase(t *testing.T) { PreviewHostnamePrefix: "preview", } rr, _ := InitAdmiral(context.Background(), p) - t.Logf(common.GetPreviewHostnamePrefix()) config := rest.Config{ Host: "localhost", } diff --git a/admiral/pkg/controller/common/common.go b/admiral/pkg/controller/common/common.go index f0b2ba29..77aa2e35 100644 --- a/admiral/pkg/controller/common/common.go +++ b/admiral/pkg/controller/common/common.go @@ -1,37 +1,39 @@ package common import ( - "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/v1" + "sort" + "strings" + + v1 "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/v1" log "github.com/sirupsen/logrus" k8sAppsV1 "k8s.io/api/apps/v1" k8sV1 "k8s.io/api/core/v1" - "sort" - "strings" ) const ( - NamespaceKubeSystem = "kube-system" - NamespaceIstioSystem = "istio-system" - Env = "env" - Http = "http" - Grpc = "grpc" - GrpcWeb = "grpc-web" - Http2 = "http2" - DefaultMtlsPort = 15443 - DefaultServiceEntryPort = 80 - Sep = "." - Dash = "-" - Slash = "/" - DotLocalDomainSuffix = ".svc.cluster.local" - Mesh = "mesh" - MulticlusterIngressGateway = "istio-multicluster-ingressgateway" - LocalAddressPrefix = "240.0" - NodeRegionLabel = "failure-domain.beta.kubernetes.io/region" - SpiffePrefix = "spiffe://" - SidecarEnabledPorts = "traffic.sidecar.istio.io/includeInboundPorts" - Default = "default" - AdmiralIgnoreAnnotation = "admiral.io/ignore" - AdmiralCnameCaseSensitive = "admiral.io/cname-case-sensitive" + NamespaceKubeSystem = "kube-system" + NamespaceIstioSystem = "istio-system" + Env = "env" + Http = "http" + Grpc = "grpc" + GrpcWeb = "grpc-web" + Http2 = "http2" + DefaultMtlsPort = 15443 + DefaultServiceEntryPort = 80 + Sep = "." + Dash = "-" + Slash = "/" + DotLocalDomainSuffix = ".svc.cluster.local" + Mesh = "mesh" + MulticlusterIngressGateway = "istio-multicluster-ingressgateway" + LocalAddressPrefix = "240.0" + NodeRegionLabel = "failure-domain.beta.kubernetes.io/region" + SpiffePrefix = "spiffe://" + SidecarEnabledPorts = "traffic.sidecar.istio.io/includeInboundPorts" + Default = "default" + AdmiralIgnoreAnnotation = "admiral.io/ignore" + AdmiralCnameCaseSensitive = "admiral.io/cname-case-sensitive" + BlueGreenRolloutPreviewPrefix = "preview" ) type Event int @@ -87,7 +89,7 @@ func GetCname(deployment *k8sAppsV1.Deployment, identifier string, nameSuffix st return strings.ToLower(cname) } -func GetCnameVal(vals[] string) string { +func GetCnameVal(vals []string) string { return strings.Join(vals, Sep) } @@ -250,4 +252,4 @@ func GetGtpEnv(gtp *v1.GlobalTrafficPolicy) string { environment = Default } return environment -} \ No newline at end of file +} diff --git a/admiral/pkg/controller/common/common_test.go b/admiral/pkg/controller/common/common_test.go index 29c19355..299196a1 100644 --- a/admiral/pkg/controller/common/common_test.go +++ b/admiral/pkg/controller/common/common_test.go @@ -1,17 +1,16 @@ package common import ( - "reflect" - "strings" - "testing" - "time" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" v12 "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/v1" k8sAppsV1 "k8s.io/api/apps/v1" k8sCoreV1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" + "reflect" + "strings" + "testing" + "time" ) var ignoreUnexported = cmpopts.IgnoreUnexported(v12.GlobalTrafficPolicy{}.Status) @@ -30,7 +29,6 @@ func init() { SecretResolver: "", WorkloadSidecarName: "default", WorkloadSidecarUpdate: "disabled", - PreviewHostnamePrefix: "preview", } p.LabelSet.WorkloadIdentityKey = "identity" diff --git a/admiral/pkg/controller/common/config.go b/admiral/pkg/controller/common/config.go index 87c4080f..8c7f0189 100644 --- a/admiral/pkg/controller/common/config.go +++ b/admiral/pkg/controller/common/config.go @@ -1,10 +1,9 @@ package common import ( + log "github.com/sirupsen/logrus" "sync" "time" - - log "github.com/sirupsen/logrus" ) var admiralParams = AdmiralParams{ @@ -72,10 +71,6 @@ func GetHostnameSuffix() string { return admiralParams.HostnameSuffix } -func GetPreviewHostnamePrefix() string { - return admiralParams.PreviewHostnamePrefix -} - func GetWorkloadIdentifier() string { return admiralParams.LabelSet.WorkloadIdentityKey } diff --git a/admiral/pkg/controller/common/config_test.go b/admiral/pkg/controller/common/config_test.go index c4ab32e6..0543105a 100644 --- a/admiral/pkg/controller/common/config_test.go +++ b/admiral/pkg/controller/common/config_test.go @@ -50,9 +50,6 @@ func TestConfigManagement(t *testing.T) { if GetHostnameSuffix() != "mesh" { t.Errorf("Hostname suffix mismatch, expected mesh, got %v", GetHostnameSuffix()) } - if GetPreviewHostnamePrefix() != "preview" { - t.Errorf("Prefix for preview hostname mismatch, expected preview, got %v", GetPreviewHostnamePrefix()) - } if GetSyncNamespace() != "ns" { t.Errorf("Sync namespace mismatch, expected ns, got %v", GetSyncNamespace()) }