github.com/kubewharf/katalyst-core@v0.5.3/pkg/controller/kcc/kcct_test.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package kcc
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  	"time"
    23  
    24  	"github.com/stretchr/testify/assert"
    25  	v1 "k8s.io/api/core/v1"
    26  	apiequality "k8s.io/apimachinery/pkg/api/equality"
    27  	"k8s.io/apimachinery/pkg/api/meta"
    28  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    29  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
    30  	"k8s.io/apimachinery/pkg/labels"
    31  	"k8s.io/apimachinery/pkg/runtime"
    32  	"k8s.io/apimachinery/pkg/util/sets"
    33  	"k8s.io/client-go/tools/cache"
    34  	"k8s.io/klog/v2"
    35  
    36  	"github.com/kubewharf/katalyst-api/pkg/apis/config/v1alpha1"
    37  	katalyst_base "github.com/kubewharf/katalyst-core/cmd/base"
    38  	"github.com/kubewharf/katalyst-core/pkg/config"
    39  	"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/crd"
    40  	kcctarget "github.com/kubewharf/katalyst-core/pkg/controller/kcc/target"
    41  	"github.com/kubewharf/katalyst-core/pkg/metrics"
    42  	"github.com/kubewharf/katalyst-core/pkg/util"
    43  	"github.com/kubewharf/katalyst-core/pkg/util/native"
    44  )
    45  
    46  func toTestUnstructured(obj interface{}) *unstructured.Unstructured {
    47  	ret, err := native.ToUnstructured(obj)
    48  	if err != nil {
    49  		klog.Error(err)
    50  	}
    51  	return ret
    52  }
    53  
    54  func testLabelSelector(t *testing.T, labelSelector string) labels.Selector {
    55  	parse, err := labels.Parse(labelSelector)
    56  	if err != nil {
    57  		t.Fatal(err)
    58  	}
    59  	return parse
    60  }
    61  
    62  func generateTestLabelSelectorTargetResource(name, labelSelector string, priority int32) util.KCCTargetResource {
    63  	return util.ToKCCTargetResource(toTestUnstructured(&v1alpha1.AdminQoSConfiguration{
    64  		ObjectMeta: metav1.ObjectMeta{
    65  			Name: name,
    66  		},
    67  		Spec: v1alpha1.AdminQoSConfigurationSpec{
    68  			GenericConfigSpec: v1alpha1.GenericConfigSpec{
    69  				NodeLabelSelector: labelSelector,
    70  				Priority:          priority,
    71  			},
    72  		},
    73  	}))
    74  }
    75  
    76  func generateTestNodeNamesTargetResource(name string, nodeNames []string) util.KCCTargetResource {
    77  	return util.ToKCCTargetResource(toTestUnstructured(&v1alpha1.AdminQoSConfiguration{
    78  		ObjectMeta: metav1.ObjectMeta{
    79  			Name: name,
    80  		},
    81  		Spec: v1alpha1.AdminQoSConfigurationSpec{
    82  			GenericConfigSpec: v1alpha1.GenericConfigSpec{
    83  				EphemeralSelector: v1alpha1.EphemeralSelector{
    84  					NodeNames: nodeNames,
    85  				},
    86  			},
    87  		},
    88  	}))
    89  }
    90  
    91  func TestKatalystCustomConfigTargetController_Run(t *testing.T) {
    92  	t.Parallel()
    93  
    94  	type args struct {
    95  		kccList              []runtime.Object
    96  		kccListChanged       []runtime.Object
    97  		kccTargetList        []runtime.Object
    98  		kccTargetListChanged []runtime.Object
    99  		kccConfig            *config.Configuration
   100  	}
   101  	tests := []struct {
   102  		name string
   103  		args args
   104  	}{
   105  		{
   106  			name: "kcc and kcc target are all valid",
   107  			args: args{
   108  				kccList: []runtime.Object{
   109  					&v1alpha1.KatalystCustomConfig{
   110  						ObjectMeta: metav1.ObjectMeta{
   111  							Name:      "test-kcc",
   112  							Namespace: "default",
   113  						},
   114  						Spec: v1alpha1.KatalystCustomConfigSpec{
   115  							TargetType: crd.AdminQoSConfigurationGVR,
   116  							NodeLabelSelectorAllowedKeyList: []v1alpha1.PriorityNodeLabelSelectorAllowedKeyList{
   117  								{
   118  									Priority: 0,
   119  									KeyList:  []string{"aa"},
   120  								},
   121  							},
   122  						},
   123  					},
   124  				},
   125  				kccTargetList: []runtime.Object{
   126  					&v1alpha1.AdminQoSConfiguration{
   127  						TypeMeta: metav1.TypeMeta{
   128  							Kind:       crd.ResourceKindAdminQoSConfiguration,
   129  							APIVersion: v1alpha1.SchemeGroupVersion.String(),
   130  						},
   131  						ObjectMeta: metav1.ObjectMeta{
   132  							Name:      "default",
   133  							Namespace: "default",
   134  						},
   135  						Spec: v1alpha1.AdminQoSConfigurationSpec{
   136  							Config: v1alpha1.AdminQoSConfig{
   137  								EvictionConfig: &v1alpha1.EvictionConfig{
   138  									ReclaimedResourcesEvictionConfig: &v1alpha1.ReclaimedResourcesEvictionConfig{
   139  										EvictionThreshold: map[v1.ResourceName]float64{
   140  											v1.ResourceCPU: 5.0,
   141  										},
   142  									},
   143  								},
   144  							},
   145  						},
   146  					},
   147  					&v1alpha1.AdminQoSConfiguration{
   148  						TypeMeta: metav1.TypeMeta{
   149  							Kind:       crd.ResourceKindAdminQoSConfiguration,
   150  							APIVersion: v1alpha1.SchemeGroupVersion.String(),
   151  						},
   152  						ObjectMeta: metav1.ObjectMeta{
   153  							Name:      "aa=bb",
   154  							Namespace: "default",
   155  						},
   156  						Spec: v1alpha1.AdminQoSConfigurationSpec{
   157  							GenericConfigSpec: v1alpha1.GenericConfigSpec{
   158  								NodeLabelSelector: "aa=bb",
   159  							},
   160  							Config: v1alpha1.AdminQoSConfig{
   161  								EvictionConfig: &v1alpha1.EvictionConfig{
   162  									ReclaimedResourcesEvictionConfig: &v1alpha1.ReclaimedResourcesEvictionConfig{
   163  										EvictionThreshold: map[v1.ResourceName]float64{
   164  											v1.ResourceCPU: 5.0,
   165  										},
   166  									},
   167  								},
   168  							},
   169  						},
   170  					},
   171  					&v1alpha1.AdminQoSConfiguration{
   172  						TypeMeta: metav1.TypeMeta{
   173  							Kind:       crd.ResourceKindAdminQoSConfiguration,
   174  							APIVersion: v1alpha1.SchemeGroupVersion.String(),
   175  						},
   176  						ObjectMeta: metav1.ObjectMeta{
   177  							Name:              "node-1",
   178  							Namespace:         "default",
   179  							CreationTimestamp: metav1.Now(),
   180  						},
   181  						Spec: v1alpha1.AdminQoSConfigurationSpec{
   182  							GenericConfigSpec: v1alpha1.GenericConfigSpec{
   183  								EphemeralSelector: v1alpha1.EphemeralSelector{
   184  									NodeNames: []string{
   185  										"node-1",
   186  									},
   187  									LastDuration: &metav1.Duration{
   188  										Duration: 10 * time.Second,
   189  									},
   190  								},
   191  							},
   192  							Config: v1alpha1.AdminQoSConfig{
   193  								EvictionConfig: &v1alpha1.EvictionConfig{
   194  									ReclaimedResourcesEvictionConfig: &v1alpha1.ReclaimedResourcesEvictionConfig{
   195  										EvictionThreshold: map[v1.ResourceName]float64{
   196  											v1.ResourceCPU: 5.0,
   197  										},
   198  									},
   199  								},
   200  							},
   201  						},
   202  					},
   203  				},
   204  			},
   205  		},
   206  		{
   207  			name: "kcc target from valid to invalid",
   208  			args: args{
   209  				kccList: []runtime.Object{
   210  					&v1alpha1.KatalystCustomConfig{
   211  						ObjectMeta: metav1.ObjectMeta{
   212  							Name:      "test-kcc",
   213  							Namespace: "default",
   214  						},
   215  						Spec: v1alpha1.KatalystCustomConfigSpec{
   216  							TargetType: crd.AdminQoSConfigurationGVR,
   217  							NodeLabelSelectorAllowedKeyList: []v1alpha1.PriorityNodeLabelSelectorAllowedKeyList{
   218  								{
   219  									Priority: 0,
   220  									KeyList:  []string{"aa"},
   221  								},
   222  							},
   223  						},
   224  					},
   225  				},
   226  				kccTargetList: []runtime.Object{
   227  					&v1alpha1.AdminQoSConfiguration{
   228  						TypeMeta: metav1.TypeMeta{
   229  							Kind:       crd.ResourceKindAdminQoSConfiguration,
   230  							APIVersion: v1alpha1.SchemeGroupVersion.String(),
   231  						},
   232  						ObjectMeta: metav1.ObjectMeta{
   233  							Name:      "config-1",
   234  							Namespace: "default",
   235  						},
   236  						Spec: v1alpha1.AdminQoSConfigurationSpec{
   237  							GenericConfigSpec: v1alpha1.GenericConfigSpec{
   238  								NodeLabelSelector: "aa=bb",
   239  							},
   240  							Config: v1alpha1.AdminQoSConfig{
   241  								EvictionConfig: &v1alpha1.EvictionConfig{
   242  									ReclaimedResourcesEvictionConfig: &v1alpha1.ReclaimedResourcesEvictionConfig{
   243  										EvictionThreshold: map[v1.ResourceName]float64{
   244  											v1.ResourceCPU: 5.0,
   245  										},
   246  									},
   247  								},
   248  							},
   249  						},
   250  					},
   251  					&v1alpha1.AdminQoSConfiguration{
   252  						TypeMeta: metav1.TypeMeta{
   253  							Kind:       crd.ResourceKindAdminQoSConfiguration,
   254  							APIVersion: v1alpha1.SchemeGroupVersion.String(),
   255  						},
   256  						ObjectMeta: metav1.ObjectMeta{
   257  							Name:      "config-2",
   258  							Namespace: "default",
   259  						},
   260  						Spec: v1alpha1.AdminQoSConfigurationSpec{
   261  							GenericConfigSpec: v1alpha1.GenericConfigSpec{
   262  								NodeLabelSelector: "aa=bb",
   263  							},
   264  							Config: v1alpha1.AdminQoSConfig{
   265  								EvictionConfig: &v1alpha1.EvictionConfig{
   266  									ReclaimedResourcesEvictionConfig: &v1alpha1.ReclaimedResourcesEvictionConfig{
   267  										EvictionThreshold: map[v1.ResourceName]float64{
   268  											v1.ResourceCPU: 5.0,
   269  										},
   270  									},
   271  								},
   272  							},
   273  						},
   274  					},
   275  				},
   276  				kccTargetListChanged: []runtime.Object{
   277  					&v1alpha1.AdminQoSConfiguration{
   278  						TypeMeta: metav1.TypeMeta{
   279  							Kind:       crd.ResourceKindAdminQoSConfiguration,
   280  							APIVersion: v1alpha1.SchemeGroupVersion.String(),
   281  						},
   282  						ObjectMeta: metav1.ObjectMeta{
   283  							Name:      "config-2",
   284  							Namespace: "default",
   285  						},
   286  						Spec: v1alpha1.AdminQoSConfigurationSpec{
   287  							GenericConfigSpec: v1alpha1.GenericConfigSpec{
   288  								NodeLabelSelector: "aa=cc",
   289  							},
   290  							Config: v1alpha1.AdminQoSConfig{
   291  								EvictionConfig: &v1alpha1.EvictionConfig{
   292  									ReclaimedResourcesEvictionConfig: &v1alpha1.ReclaimedResourcesEvictionConfig{
   293  										EvictionThreshold: map[v1.ResourceName]float64{
   294  											v1.ResourceCPU: 5.0,
   295  										},
   296  									},
   297  								},
   298  							},
   299  						},
   300  					},
   301  				},
   302  			},
   303  		},
   304  	}
   305  	for _, tt := range tests {
   306  		tt := tt
   307  		t.Run(tt.name, func(t *testing.T) {
   308  			t.Parallel()
   309  
   310  			genericContext, err := katalyst_base.GenerateFakeGenericContext(nil, tt.args.kccList, tt.args.kccTargetList)
   311  			assert.NoError(t, err)
   312  			conf := generateTestConfiguration(t)
   313  
   314  			ctx := context.Background()
   315  			targetHandler := kcctarget.NewKatalystCustomConfigTargetHandler(
   316  				ctx,
   317  				genericContext.Client,
   318  				conf.ControllersConfiguration.KCCConfig,
   319  				genericContext.InternalInformerFactory.Config().V1alpha1().KatalystCustomConfigs(),
   320  			)
   321  
   322  			targetController, err := NewKatalystCustomConfigTargetController(
   323  				ctx,
   324  				conf.GenericConfiguration,
   325  				conf.GenericControllerConfiguration,
   326  				conf.KCCConfig,
   327  				genericContext.Client,
   328  				genericContext.InternalInformerFactory.Config().V1alpha1().KatalystCustomConfigs(),
   329  				metrics.DummyMetrics{},
   330  				targetHandler,
   331  			)
   332  			assert.NoError(t, err)
   333  
   334  			genericContext.StartInformer(ctx)
   335  			go targetHandler.Run()
   336  			go targetController.Run()
   337  
   338  			cache.WaitForCacheSync(targetController.ctx.Done(), targetController.syncedFunc...)
   339  			time.Sleep(1 * time.Second)
   340  
   341  			for _, kcc := range tt.args.kccListChanged {
   342  				_, err := genericContext.Client.InternalClient.ConfigV1alpha1().CustomNodeConfigs().Update(ctx, kcc.(*v1alpha1.CustomNodeConfig), metav1.UpdateOptions{})
   343  				assert.NoError(t, err)
   344  			}
   345  			time.Sleep(1 * time.Second)
   346  
   347  			for _, kccTarget := range tt.args.kccTargetListChanged {
   348  				gvr, _ := meta.UnsafeGuessKindToResource(kccTarget.GetObjectKind().GroupVersionKind())
   349  				obj := toTestUnstructured(kccTarget)
   350  				_, err := genericContext.Client.DynamicClient.Resource(gvr).Namespace(obj.GetNamespace()).Update(ctx, obj, metav1.UpdateOptions{})
   351  				assert.NoError(t, err)
   352  			}
   353  			time.Sleep(1 * time.Second)
   354  		})
   355  	}
   356  }
   357  
   358  func Test_validateLabelSelectorWithOthers(t *testing.T) {
   359  	t.Parallel()
   360  
   361  	type args struct {
   362  		priorityAllowedKeyListMap map[int32]sets.String
   363  		targetResource            util.KCCTargetResource
   364  		otherResources            []util.KCCTargetResource
   365  	}
   366  	tests := []struct {
   367  		name    string
   368  		args    args
   369  		want    bool
   370  		wantErr bool
   371  	}{
   372  		{
   373  			name: "test-1",
   374  			args: args{
   375  				priorityAllowedKeyListMap: map[int32]sets.String{
   376  					0: sets.NewString("aa"),
   377  				},
   378  				targetResource: generateTestLabelSelectorTargetResource("1", "aa=bb", 0),
   379  				otherResources: []util.KCCTargetResource{
   380  					generateTestLabelSelectorTargetResource("2", "aa=cc", 0),
   381  				},
   382  			},
   383  			want: true,
   384  		},
   385  		{
   386  			name: "test-2",
   387  			args: args{
   388  				priorityAllowedKeyListMap: map[int32]sets.String{
   389  					0: sets.NewString("aa"),
   390  				},
   391  				targetResource: generateTestLabelSelectorTargetResource("1", "aa=bb", 0),
   392  				otherResources: []util.KCCTargetResource{
   393  					generateTestLabelSelectorTargetResource("2", "aa in (cc,dd)", 0),
   394  				},
   395  			},
   396  			want: true,
   397  		},
   398  		{
   399  			name: "test-3",
   400  			args: args{
   401  				priorityAllowedKeyListMap: map[int32]sets.String{
   402  					0: sets.NewString("aa"),
   403  				},
   404  				targetResource: generateTestLabelSelectorTargetResource("1", "aa=bb", 0),
   405  				otherResources: []util.KCCTargetResource{
   406  					generateTestLabelSelectorTargetResource("2", "aa in (bb,cc)", 0),
   407  				},
   408  			},
   409  			want: false,
   410  		},
   411  		{
   412  			name: "test-4",
   413  			args: args{
   414  				priorityAllowedKeyListMap: map[int32]sets.String{
   415  					0: sets.NewString("aa"),
   416  				},
   417  				targetResource: generateTestLabelSelectorTargetResource("1", "aa=bb", 0),
   418  				otherResources: []util.KCCTargetResource{
   419  					generateTestLabelSelectorTargetResource("2", "aa notin (bb,cc)", 0),
   420  				},
   421  			},
   422  			want: true,
   423  		},
   424  	}
   425  	for _, tt := range tests {
   426  		tt := tt
   427  		t.Run(tt.name, func(t *testing.T) {
   428  			t.Parallel()
   429  
   430  			got, _, _, err := validateLabelSelectorOverlapped(tt.args.priorityAllowedKeyListMap, tt.args.targetResource, tt.args.otherResources)
   431  			if (err != nil) != tt.wantErr {
   432  				t.Errorf("validateLabelSelectorOverlapped() error = %v, wantErr %v", err, tt.wantErr)
   433  				return
   434  			}
   435  			if got != tt.want {
   436  				t.Errorf("validateLabelSelectorOverlapped() got = %v, want %v", got, tt.want)
   437  			}
   438  		})
   439  	}
   440  }
   441  
   442  func Test_validateTargetResourceNodeNamesWithOthers(t *testing.T) {
   443  	t.Parallel()
   444  
   445  	type args struct {
   446  		targetResource util.KCCTargetResource
   447  		otherResources []util.KCCTargetResource
   448  	}
   449  	tests := []struct {
   450  		name    string
   451  		args    args
   452  		want    bool
   453  		wantErr bool
   454  	}{
   455  		{
   456  			name: "test-1",
   457  			args: args{
   458  				targetResource: generateTestNodeNamesTargetResource("1", []string{"node-1"}),
   459  				otherResources: []util.KCCTargetResource{
   460  					generateTestNodeNamesTargetResource("2", []string{"node-2"}),
   461  				},
   462  			},
   463  			want: true,
   464  		},
   465  		{
   466  			name: "test-2",
   467  			args: args{
   468  				targetResource: generateTestNodeNamesTargetResource("1", []string{"node-1"}),
   469  				otherResources: []util.KCCTargetResource{
   470  					generateTestNodeNamesTargetResource("2", []string{"node-2", "node-3"}),
   471  				},
   472  			},
   473  			want: true,
   474  		},
   475  		{
   476  			name: "test-3",
   477  			args: args{
   478  				targetResource: generateTestNodeNamesTargetResource("1", []string{"node-1"}),
   479  				otherResources: []util.KCCTargetResource{
   480  					generateTestNodeNamesTargetResource("2", []string{"node-1", "node-3"}),
   481  				},
   482  			},
   483  			want: false,
   484  		},
   485  		{
   486  			name: "test-4",
   487  			args: args{
   488  				targetResource: generateTestNodeNamesTargetResource("1", []string{"node-1", "node-2"}),
   489  				otherResources: []util.KCCTargetResource{
   490  					generateTestNodeNamesTargetResource("2", []string{"node-3", "node-4"}),
   491  				},
   492  			},
   493  			want: true,
   494  		},
   495  	}
   496  	for _, tt := range tests {
   497  		tt := tt
   498  		t.Run(tt.name, func(t *testing.T) {
   499  			t.Parallel()
   500  
   501  			got, _, _, err := validateTargetResourceNodeNamesOverlapped(tt.args.targetResource, tt.args.otherResources)
   502  			if (err != nil) != tt.wantErr {
   503  				t.Errorf("validateTargetResourceNodeNamesOverlapped() error = %v, wantErr %v", err, tt.wantErr)
   504  				return
   505  			}
   506  			if got != tt.want {
   507  				t.Errorf("validateTargetResourceNodeNamesOverlapped() got = %v, want %v", got, tt.want)
   508  			}
   509  		})
   510  	}
   511  }
   512  
   513  func Test_validateTargetResourceGlobalWithOthers(t *testing.T) {
   514  	t.Parallel()
   515  
   516  	type args struct {
   517  		targetResource util.KCCTargetResource
   518  		otherResources []util.KCCTargetResource
   519  	}
   520  	tests := []struct {
   521  		name    string
   522  		args    args
   523  		want    bool
   524  		wantErr bool
   525  	}{
   526  		{
   527  			name: "test-1",
   528  			args: args{
   529  				targetResource: generateTestLabelSelectorTargetResource("1", "", 0),
   530  				otherResources: []util.KCCTargetResource{
   531  					generateTestLabelSelectorTargetResource("2", "", 0),
   532  				},
   533  			},
   534  			want: false,
   535  		},
   536  		{
   537  			name: "test-2",
   538  			args: args{
   539  				targetResource: generateTestLabelSelectorTargetResource("1", "", 0),
   540  				otherResources: []util.KCCTargetResource{
   541  					generateTestLabelSelectorTargetResource("1", "", 0),
   542  					generateTestLabelSelectorTargetResource("2", "aa=bb", 0),
   543  				},
   544  			},
   545  			want: true,
   546  		},
   547  	}
   548  	for _, tt := range tests {
   549  		tt := tt
   550  		t.Run(tt.name, func(t *testing.T) {
   551  			t.Parallel()
   552  
   553  			got, _, _, err := validateTargetResourceGlobalOverlapped(tt.args.targetResource, tt.args.otherResources)
   554  			if (err != nil) != tt.wantErr {
   555  				t.Errorf("validateTargetResourceGlobalOverlapped() error = %v, wantErr %v", err, tt.wantErr)
   556  				return
   557  			}
   558  			if got != tt.want {
   559  				t.Errorf("validateTargetResourceGlobalOverlapped() got = %v, want %v", got, tt.want)
   560  			}
   561  		})
   562  	}
   563  }
   564  
   565  func Test_updateTargetResourceStatus(t *testing.T) {
   566  	t.Parallel()
   567  
   568  	type args struct {
   569  		targetResource util.KCCTargetResource
   570  		isValid        bool
   571  		msg            string
   572  		reason         string
   573  	}
   574  	tests := []struct {
   575  		name         string
   576  		args         args
   577  		wantResource util.KCCTargetResource
   578  		equalFunc    func(util.KCCTargetResource, util.KCCTargetResource) bool
   579  	}{
   580  		{
   581  			name: "test-1",
   582  			args: args{
   583  				targetResource: util.ToKCCTargetResource(toTestUnstructured(&v1alpha1.AdminQoSConfiguration{
   584  					ObjectMeta: metav1.ObjectMeta{
   585  						Name: "config-1",
   586  					},
   587  					Spec: v1alpha1.AdminQoSConfigurationSpec{
   588  						GenericConfigSpec: v1alpha1.GenericConfigSpec{
   589  							NodeLabelSelector: "aa=bb",
   590  						},
   591  					},
   592  				})),
   593  				isValid: false,
   594  				msg:     "ssasfr",
   595  				reason:  "dasf",
   596  			},
   597  			wantResource: util.ToKCCTargetResource(toTestUnstructured(&v1alpha1.AdminQoSConfiguration{
   598  				ObjectMeta: metav1.ObjectMeta{
   599  					Name: "config-1",
   600  				},
   601  				Spec: v1alpha1.AdminQoSConfigurationSpec{
   602  					GenericConfigSpec: v1alpha1.GenericConfigSpec{
   603  						NodeLabelSelector: "aa=bb",
   604  					},
   605  				},
   606  				Status: v1alpha1.GenericConfigStatus{
   607  					Conditions: []v1alpha1.GenericConfigCondition{
   608  						{
   609  							Type:    v1alpha1.ConfigConditionTypeValid,
   610  							Status:  v1.ConditionFalse,
   611  							Reason:  "dasf",
   612  							Message: "ssasfr",
   613  						},
   614  					},
   615  				},
   616  			})),
   617  			equalFunc: func(t1 util.KCCTargetResource, t2 util.KCCTargetResource) bool {
   618  				status1 := t1.GetGenericStatus()
   619  				status2 := t2.GetGenericStatus()
   620  				if len(status1.Conditions) != len(status2.Conditions) {
   621  					return false
   622  				}
   623  
   624  				status1.Conditions[0].LastTransitionTime = metav1.Time{}
   625  				status2.Conditions[0].LastTransitionTime = metav1.Time{}
   626  				t1.SetGenericStatus(status1)
   627  				t2.SetGenericStatus(status2)
   628  				if !apiequality.Semantic.DeepEqual(t1, t2) {
   629  					return false
   630  				}
   631  
   632  				return true
   633  			},
   634  		},
   635  	}
   636  	for _, tt := range tests {
   637  		tt := tt
   638  		t.Run(tt.name, func(t *testing.T) {
   639  			t.Parallel()
   640  
   641  			if updateTargetResourceStatus(tt.args.targetResource, tt.args.isValid, tt.args.msg, tt.args.reason); !tt.equalFunc(tt.args.targetResource, tt.wantResource) {
   642  				t.Errorf("updateTargetResourceStatus() = %v, want %v", tt.args.targetResource.GetGenericStatus(), tt.wantResource.GetGenericStatus())
   643  			}
   644  		})
   645  	}
   646  }
   647  
   648  func Test_checkLabelSelectorOverlap(t *testing.T) {
   649  	t.Parallel()
   650  
   651  	type args struct {
   652  		selector      labels.Selector
   653  		otherSelector labels.Selector
   654  		keyList       []string
   655  	}
   656  	tests := []struct {
   657  		name string
   658  		args args
   659  		want bool
   660  	}{
   661  		{
   662  			name: "test-1",
   663  			args: args{
   664  				selector:      testLabelSelector(t, "label1=aa"),
   665  				otherSelector: testLabelSelector(t, "label1=bb"),
   666  				keyList:       []string{"label1"},
   667  			},
   668  			want: false,
   669  		},
   670  		{
   671  			name: "test-2",
   672  			args: args{
   673  				selector:      testLabelSelector(t, "label1=aa"),
   674  				otherSelector: testLabelSelector(t, "label1!=bb"),
   675  				keyList:       []string{"label1"},
   676  			},
   677  			want: true,
   678  		},
   679  		{
   680  			name: "test-3",
   681  			args: args{
   682  				selector:      testLabelSelector(t, "label1=aa"),
   683  				otherSelector: testLabelSelector(t, "label1 in (aa,bb)"),
   684  				keyList:       []string{"label1"},
   685  			},
   686  			want: true,
   687  		},
   688  		{
   689  			name: "test-4",
   690  			args: args{
   691  				selector:      testLabelSelector(t, "label1=aa"),
   692  				otherSelector: testLabelSelector(t, "label1 notin (aa,bb)"),
   693  				keyList:       []string{"label1"},
   694  			},
   695  			want: false,
   696  		},
   697  		{
   698  			name: "test-5",
   699  			args: args{
   700  				selector:      testLabelSelector(t, "label1=aa"),
   701  				otherSelector: testLabelSelector(t, "label1 in (aa,bb),label2=cc"),
   702  				keyList:       []string{"label1", "label2"},
   703  			},
   704  			want: true,
   705  		},
   706  		{
   707  			name: "test-6",
   708  			args: args{
   709  				selector:      testLabelSelector(t, "label1=aa"),
   710  				otherSelector: testLabelSelector(t, "label2=bb"),
   711  				keyList:       []string{"label1", "label2"},
   712  			},
   713  			want: true,
   714  		},
   715  		{
   716  			name: "test-7",
   717  			args: args{
   718  				selector:      testLabelSelector(t, "label1 notin (aa, bb),label2=bb"),
   719  				otherSelector: testLabelSelector(t, "label1 in (aa),label2=bb"),
   720  				keyList:       []string{"label1", "label2"},
   721  			},
   722  			want: false,
   723  		},
   724  		{
   725  			name: "test-8",
   726  			args: args{
   727  				selector:      testLabelSelector(t, "label1 in (aa),label2 notin (bb,cc)"),
   728  				otherSelector: testLabelSelector(t, "label1 notin (cc,dd),label2 notin (cc)"),
   729  				keyList:       []string{"label1", "label2"},
   730  			},
   731  			want: true,
   732  		},
   733  		{
   734  			name: "test-9",
   735  			args: args{
   736  				selector:      testLabelSelector(t, "label1=aa"),
   737  				otherSelector: testLabelSelector(t, "label1 notin (cc,dd),label2 notin (cc)"),
   738  				keyList:       []string{"label1", "label2"},
   739  			},
   740  			want: true,
   741  		},
   742  	}
   743  	for _, tt := range tests {
   744  		tt := tt
   745  		t.Run(tt.name, func(t *testing.T) {
   746  			t.Parallel()
   747  			assert.Equalf(t, tt.want, checkLabelSelectorOverlap(tt.args.selector, tt.args.otherSelector, tt.args.keyList), "checkLabelSelectorOverlap(%v, %v, %v)", tt.args.selector, tt.args.otherSelector, tt.args.keyList)
   748  		})
   749  	}
   750  }