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

MESH-6000: ignore argo tracking tags during VS copy #375

Merged
merged 4 commits into from
Jan 8, 2025
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
2 changes: 1 addition & 1 deletion admiral/cmd/admiral/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ func GetRootCmd(args []string) *cobra.Command {
rootCmd.PersistentFlags().BoolVar(&params.EnableSWAwareNSCaches, "enable_sw_aware_ns_caches", false, "Enable/Disable SW Aware NS Caches")
rootCmd.PersistentFlags().BoolVar(&params.AdmiralStateSyncerMode, "admiral_state_syncer_mode", false, "Enable/Disable admiral to run as state syncer only")
rootCmd.PersistentFlags().Int64Var(&params.DefaultWarmupDurationSecs, "default_warmup_duration_in_seconds", 45, "The default value for the warmupDurationSecs to be used on Destination Rules created by admiral")

rootCmd.PersistentFlags().BoolVar(&params.EnableGenerationCheck, "enable_generation_check", true, "Enable/Disable Generation Check")
rootCmd.PersistentFlags().BoolVar(&params.EnableIsOnlyReplicaCountChangedCheck, "enable_replica_count_check", false, "Enable/Disable Replica Count Check")
rootCmd.PersistentFlags().BoolVar(&params.ClientInitiatedProcessingEnabled, "client_initiated_processing_enabled", true, "Enable/Disable Client Initiated Processing")
rootCmd.PersistentFlags().BoolVar(&params.PreventSplitBrain, "prevent_split_brain", true, "Enable/Disable Explicit Split Brain prevention logic")
rootCmd.PersistentFlags().StringSliceVar(&params.IgnoreLabelsAnnotationsVSCopyList, "ignore_labels_annotations_vs_copy_list", []string{"applications.argoproj.io/app-name", "app.kubernetes.io/instance", "argocd.argoproj.io/tracking-id"}, "Labels and annotations that should not be preserved during VS copy")

//Admiral 2.0 flags
rootCmd.PersistentFlags().BoolVar(&params.AdmiralOperatorMode, "admiral_operator_mode", false, "Enable/Disable admiral operator functionality")
Expand Down
6 changes: 6 additions & 0 deletions admiral/pkg/clusters/virtualservice_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,12 @@ func addUpdateVirtualService(
skipAddingExportTo = true
}

// remove ignored labels and annotations from NewCopy (deleting on nil map or nonexistent keys is a no-op)
for _, ignored := range common.GetIgnoreLabelsAnnotationsVSCopy() {
delete(newCopy.Labels, ignored)
delete(newCopy.Annotations, ignored)
}
rtay1188 marked this conversation as resolved.
Show resolved Hide resolved

if common.EnableExportTo(newCopy.Spec.Hosts[0]) && !skipAddingExportTo {
sortedDependentNamespaces := getSortedDependentNamespaces(rr.AdmiralCache, newCopy.Spec.Hosts[0], rc.ClusterID, ctxLogger)
newCopy.Spec.ExportTo = sortedDependentNamespaces
Expand Down
25 changes: 21 additions & 4 deletions admiral/pkg/clusters/virtualservice_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,9 @@ func TestAddUpdateVirtualService(t *testing.T) {
namespace = "testns"
fooVS = &apiNetworkingV1Alpha3.VirtualService{
ObjectMeta: metaV1.ObjectMeta{
Name: "stage.test00.foo-vs",
Name: "stage.test00.foo-vs",
Labels: map[string]string{"applications.argoproj.io/app-name": "test", "app.kubernetes.io/instance": "test"},
Annotations: map[string]string{"argocd.argoproj.io/tracking-id": "test"},
},
Spec: networkingV1Alpha3.VirtualService{
Hosts: []string{"stage.test00.foo", "stage.test00.bar"},
Expand All @@ -1789,10 +1791,13 @@ func TestAddUpdateVirtualService(t *testing.T) {
},
}
admiralParams := common.AdmiralParams{
LabelSet: &common.LabelSet{},
SyncNamespace: "test-sync-ns",
EnableSWAwareNSCaches: true,
LabelSet: &common.LabelSet{},
SyncNamespace: "test-sync-ns",
EnableSWAwareNSCaches: true,
IgnoreLabelsAnnotationsVSCopyList: []string{"applications.argoproj.io/app-name", "app.kubernetes.io/instance", "argocd.argoproj.io/tracking-id"},
}
common.ResetSync()
common.InitializeConfig(admiralParams)
rr := NewRemoteRegistry(ctx, admiralParams)

cases := []struct {
Expand All @@ -1818,6 +1823,18 @@ func TestAddUpdateVirtualService(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
addUpdateVirtualService(ctxLogger, ctx, c.newVS, c.existingVS, namespace, rc, rr)
vs, err := istioClientWithExistingVS.NetworkingV1alpha3().VirtualServices(namespace).Get(ctx, fooVS.Name, metaV1.GetOptions{})
if err != nil {
t.Errorf("failed to get VS with error: %v", err)
}
for _, ignored := range common.GetIgnoreLabelsAnnotationsVSCopy() {
if vs.Labels[ignored] != "" {
t.Errorf("expected VS to not ignored labels, but got labels: %v", ignored)
}
if vs.Annotations[ignored] != "" {
t.Errorf("expected VS to not ignored annotations, but got annotations: %v", ignored)
}
}
})
}
}
6 changes: 6 additions & 0 deletions admiral/pkg/controller/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,9 @@ func GetOperatorSecretFilterTags() string {
defer wrapper.RUnlock()
return wrapper.params.OperatorSecretFilterTags
}

func GetIgnoreLabelsAnnotationsVSCopy() []string {
wrapper.RLock()
defer wrapper.RUnlock()
return wrapper.params.IgnoreLabelsAnnotationsVSCopyList
}
5 changes: 5 additions & 0 deletions admiral/pkg/controller/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func setupForConfigTests() {
AdditionalEndpointSuffixes: []string{"suffix1", "suffix2"},
AdditionalEndpointLabelFilters: []string{"label1", "label2"},
EnableWorkloadDataStorage: true,
IgnoreLabelsAnnotationsVSCopyList: []string{"applications.argoproj.io/app-name", "app.kubernetes.io/instance", "argocd.argoproj.io/tracking-id"},
}
ResetSync()
initHappened = true
Expand Down Expand Up @@ -488,6 +489,10 @@ func TestConfigManagement(t *testing.T) {
if !GetEnableWorkloadDataStorage() {
t.Errorf("Enable workload data storage mismatch, expected true, got %v", GetEnableWorkloadDataStorage())
}

if len(GetIgnoreLabelsAnnotationsVSCopy()) != 3 {
t.Errorf("ignored labels and annotations for VS copy mismatch, expected 3, got %v", GetIgnoreLabelsAnnotationsVSCopy())
}
}

func TestGetCRDIdentityLabelWithCRDIdentity(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions admiral/pkg/controller/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type AdmiralParams struct {
EnableGenerationCheck bool
EnableIsOnlyReplicaCountChangedCheck bool
PreventSplitBrain bool
IgnoreLabelsAnnotationsVSCopyList []string

// Cartographer specific params
TrafficConfigPersona bool
Expand Down