Add goci lint. (#243)

* Add goci lint.

Signed-off-by: xuezhaojun <zxue@redhat.com>

* handle errs and remove unused.

Signed-off-by: xuezhaojun <zxue@redhat.com>

* fix fail and remove unused code.

Signed-off-by: xuezhaojun <zxue@redhat.com>
This commit is contained in:
xuezhaojun
2022-05-10 02:50:42 -04:00
committed by GitHub
parent 25373ddab3
commit 11efeb18b5
21 changed files with 110 additions and 65 deletions
+5 -1
View File
@@ -74,7 +74,11 @@ update: copy-crd
verify-crds:
bash -x hack/verify-crds.sh
verify: verify-crds
verify-gocilint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
golangci-lint run --timeout=3m --modules-download-mode vendor ./...
verify: verify-crds verify-gocilint
update-csv: ensure-operator-sdk
cd deploy/cluster-manager && ../../$(OPERATOR_SDK) generate bundle --manifests --deploy-dir config/ --crds-dir config/crds/ --output-dir olm-catalog/cluster-manager/ --version $(CSV_VERSION)
+3 -2
View File
@@ -83,8 +83,9 @@ func needNewSigningCertKeyPair(secret *corev1.Secret) string {
maxWait := cert.NotAfter.Sub(cert.NotBefore) / 5
latestTime := cert.NotAfter.Add(-maxWait)
if time.Now().After(latestTime) {
return fmt.Sprintf("expired in %6.3f seconds", cert.NotAfter.Sub(time.Now()).Seconds())
now := time.Now()
if now.After(latestTime) {
return fmt.Sprintf("expired in %6.3f seconds", cert.NotAfter.Sub(now).Seconds())
}
return ""
+3 -2
View File
@@ -90,8 +90,9 @@ func needNewTargetCertKeyPair(secret *corev1.Secret, caBundleCerts []*x509.Certi
maxWait := cert.NotAfter.Sub(cert.NotBefore) / 5
latestTime := cert.NotAfter.Add(-maxWait)
if time.Now().After(latestTime) {
return fmt.Sprintf("expired in %6.3f seconds", cert.NotAfter.Sub(time.Now()).Seconds())
now := time.Now()
if now.After(latestTime) {
return fmt.Sprintf("expired in %6.3f seconds", cert.NotAfter.Sub(now).Seconds())
}
// check the signer common name against all the common names in our ca bundle so we don't refresh early
+9 -3
View File
@@ -90,7 +90,9 @@ func TestKlusterletSecretQueueKeyFunc(t *testing.T) {
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(c.klusterlet)
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
store := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
store.Add(c.klusterlet)
if err := store.Add(c.klusterlet); err != nil {
t.Fatal(err)
}
keyFunc := KlusterletSecretQueueKeyFunc(operatorInformers.Operator().V1().Klusterlets().Lister())
actualKey := keyFunc(c.object)
if actualKey != c.expectedKey {
@@ -138,7 +140,9 @@ func TestKlusterletDeploymentQueueKeyFunc(t *testing.T) {
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(c.klusterlet)
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
store := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
store.Add(c.klusterlet)
if err := store.Add(c.klusterlet); err != nil {
t.Fatal(err)
}
keyFunc := KlusterletDeploymentQueueKeyFunc(operatorInformers.Operator().V1().Klusterlets().Lister())
actualKey := keyFunc(c.object)
if actualKey != c.expectedKey {
@@ -204,7 +208,9 @@ func TestClusterManagerDeploymentQueueKeyFunc(t *testing.T) {
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(c.clusterManager)
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
store := operatorInformers.Operator().V1().ClusterManagers().Informer().GetStore()
store.Add(c.clusterManager)
if err := store.Add(c.clusterManager); err != nil {
t.Fatal(err)
}
keyFunc := ClusterManagerDeploymentQueueKeyFunc(operatorInformers.Operator().V1().ClusterManagers().Lister())
actualKey := keyFunc(c.object)
if actualKey != c.expectedKey {
@@ -156,7 +156,9 @@ func TestCertRotation(t *testing.T) {
operatorInformers := operatorinformers.NewSharedInformerFactory(operatorClient, 5*time.Minute)
clusterManagerStore := operatorInformers.Operator().V1().ClusterManagers().Informer().GetStore()
for _, clusterManager := range clusterManagers {
clusterManagerStore.Add(clusterManager)
if err := clusterManagerStore.Add(clusterManager); err != nil {
t.Fatal(err)
}
}
syncContext := testinghelper.NewFakeSyncContext(t, c.queueKey)
@@ -118,7 +118,6 @@ var (
const (
clusterManagerFinalizer = "operator.open-cluster-management.io/cluster-manager-cleanup"
clusterManagerApplied = "Applied"
clusterManagerAvailable = "Available"
caBundleConfigmap = "ca-bundle-configmap"
)
@@ -61,7 +61,7 @@ func newClusterManager(name string) *operatorapiv1.ClusterManager {
}
}
func newTestController(clustermanager *operatorapiv1.ClusterManager) *testController {
func newTestController(t *testing.T, clustermanager *operatorapiv1.ClusterManager) *testController {
kubeClient := fakekube.NewSimpleClientset()
kubeInfomers := kubeinformers.NewSharedInformerFactory(kubeClient, 5*time.Minute)
fakeOperatorClient := fakeoperatorlient.NewSimpleClientset(clustermanager)
@@ -75,7 +75,9 @@ func newTestController(clustermanager *operatorapiv1.ClusterManager) *testContro
}
store := operatorInformers.Operator().V1().ClusterManagers().Informer().GetStore()
store.Add(clustermanager)
if err := store.Add(clustermanager); err != nil {
t.Fatal(err)
}
return &testController{
clusterManagerController: clusterManagerController,
@@ -128,7 +130,7 @@ func ensureObject(t *testing.T, object runtime.Object, hubCore *operatorapiv1.Cl
// TestSyncDeploy tests sync manifests of hub component
func TestSyncDeploy(t *testing.T) {
clusterManager := newClusterManager("testhub")
tc := newTestController(clusterManager)
tc := newTestController(t, clusterManager)
setup(t, tc)
syncContext := testinghelper.NewFakeSyncContext(t, "testhub")
@@ -190,7 +192,7 @@ func TestSyncDelete(t *testing.T) {
now := metav1.Now()
clusterManager.ObjectMeta.SetDeletionTimestamp(&now)
tc := newTestController(clusterManager)
tc := newTestController(t, clusterManager)
setup(t, tc)
syncContext := testinghelper.NewFakeSyncContext(t, "testhub")
@@ -252,7 +254,7 @@ func TestDeleteCRD(t *testing.T) {
},
}
tc := newTestController(clusterManager)
tc := newTestController(t, clusterManager)
setup(t, tc, crd)
// Return crd with the first get, and return not found with the 2nd get
@@ -178,11 +178,6 @@ func assertActions(t *testing.T, actualActions []clienttesting.Action, expectedV
}
}
// AssertNoActions asserts no actions are happened
func assertNoActions(t *testing.T, actualActions []clienttesting.Action) {
assertActions(t, actualActions)
}
func assertStorageVersionMigration(t *testing.T, name string, object runtime.Object) {
migration, ok := object.(*migrationv1alpha1.StorageVersionMigration)
if !ok {
@@ -155,14 +155,18 @@ func TestSyncStatus(t *testing.T) {
kubeInformers := kubeinformers.NewSharedInformerFactory(fakeKubeClient, 5*time.Minute)
deployStore := kubeInformers.Apps().V1().Deployments().Informer().GetStore()
for _, deployment := range c.deployments {
deployStore.Add(deployment)
if err := deployStore.Add(deployment); err != nil {
t.Fatal(err)
}
}
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(c.clusterManagers...)
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
clusterManagerStore := operatorInformers.Operator().V1().ClusterManagers().Informer().GetStore()
for _, clusterManager := range c.clusterManagers {
clusterManagerStore.Add(clusterManager)
if err := clusterManagerStore.Add(clusterManager); err != nil {
t.Fatal(err)
}
}
controller := &clusterManagerStatusController{
@@ -107,14 +107,18 @@ func TestSync(t *testing.T) {
for _, object := range c.objects {
switch object.(type) {
case *corev1.Secret:
secretStore.Add(object)
if err := secretStore.Add(object); err != nil {
t.Fatal(err)
}
}
}
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset()
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
operatorStore := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
operatorStore.Add(newKlusterlet("test", "test"))
if err := operatorStore.Add(newKlusterlet("test", "test")); err != nil {
t.Fatal(err)
}
controller := &bootstrapController{
kubeClient: fakeKubeClient,
@@ -164,7 +168,9 @@ func TestBootstrapSecretQueueKeyFunc(t *testing.T) {
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(c.klusterlet)
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
store := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
store.Add(c.klusterlet)
if err := store.Add(c.klusterlet); err != nil {
t.Fatal(err)
}
keyFunc := bootstrapSecretQueueKeyFunc(operatorInformers.Operator().V1().Klusterlets().Lister())
actualKey := keyFunc(c.object)
if actualKey != c.expectedKey {
@@ -125,7 +125,7 @@ func newServiceAccount(name, namespace string, referenceSecret string) *corev1.S
}
}
func newTestController(klusterlet *opratorapiv1.Klusterlet, appliedManifestWorks []runtime.Object, objects ...runtime.Object) *testController {
func newTestController(t *testing.T, klusterlet *opratorapiv1.Klusterlet, appliedManifestWorks []runtime.Object, objects ...runtime.Object) *testController {
fakeKubeClient := fakekube.NewSimpleClientset(objects...)
fakeAPIExtensionClient := fakeapiextensions.NewSimpleClientset()
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(klusterlet)
@@ -149,7 +149,9 @@ func newTestController(klusterlet *opratorapiv1.Klusterlet, appliedManifestWorks
}
store := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
store.Add(klusterlet)
if err := store.Add(klusterlet); err != nil {
t.Fatal(err)
}
return &testController{
controller: hubController,
@@ -162,7 +164,7 @@ func newTestController(klusterlet *opratorapiv1.Klusterlet, appliedManifestWorks
}
}
func newTestControllerHosted(klusterlet *opratorapiv1.Klusterlet, appliedManifestWorks []runtime.Object, objects ...runtime.Object) *testController {
func newTestControllerHosted(t *testing.T, klusterlet *opratorapiv1.Klusterlet, appliedManifestWorks []runtime.Object, objects ...runtime.Object) *testController {
fakeKubeClient := fakekube.NewSimpleClientset(objects...)
fakeAPIExtensionClient := fakeapiextensions.NewSimpleClientset()
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(klusterlet)
@@ -241,7 +243,9 @@ func newTestControllerHosted(klusterlet *opratorapiv1.Klusterlet, appliedManifes
}
store := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
store.Add(klusterlet)
if err := store.Add(klusterlet); err != nil {
t.Fatal(err)
}
return &testController{
controller: hubController,
@@ -289,9 +293,11 @@ func assertRegistrationDeployment(t *testing.T, actions []clienttesting.Action,
deployment := getDeployments(actions, verb, "registration-agent")
if deployment == nil {
t.Errorf("registration deployment not found")
return
}
if len(deployment.Spec.Template.Spec.Containers) != 1 {
t.Errorf("Expect 1 containers in deployment spec, actual %d", len(deployment.Spec.Template.Spec.Containers))
return
}
args := deployment.Spec.Template.Spec.Containers[0].Args
@@ -313,10 +319,12 @@ func assertRegistrationDeployment(t *testing.T, actions []clienttesting.Action,
if !equality.Semantic.DeepEqual(args, expectedArgs) {
t.Errorf("Expect args %v, but got %v", expectedArgs, args)
return
}
if *deployment.Spec.Replicas != replica {
t.Errorf("Unexpected registration replica, expect %d, got %d", replica, *deployment.Spec.Replicas)
return
}
}
@@ -324,9 +332,11 @@ func assertWorkDeployment(t *testing.T, actions []clienttesting.Action, verb, cl
deployment := getDeployments(actions, verb, "work-agent")
if deployment == nil {
t.Errorf("work deployment not found")
return
}
if len(deployment.Spec.Template.Spec.Containers) != 1 {
t.Errorf("Expect 1 containers in deployment spec, actual %d", len(deployment.Spec.Template.Spec.Containers))
return
}
args := deployment.Spec.Template.Spec.Containers[0].Args
expectArgs := []string{
@@ -346,9 +356,11 @@ func assertWorkDeployment(t *testing.T, actions []clienttesting.Action, verb, cl
if !equality.Semantic.DeepEqual(args, expectArgs) {
t.Errorf("Expect args %v, but got %v", expectArgs, args)
return
}
if *deployment.Spec.Replicas != replica {
t.Errorf("Unexpected registration replica, expect %d, got %d", replica, *deployment.Spec.Replicas)
return
}
}
@@ -356,6 +368,7 @@ func ensureObject(t *testing.T, object runtime.Object, klusterlet *opratorapiv1.
access, err := meta.Accessor(object)
if err != nil {
t.Errorf("Unable to access objectmeta: %v", err)
return
}
namespace := helpers.AgentNamespace(klusterlet)
@@ -367,6 +380,7 @@ func ensureObject(t *testing.T, object runtime.Object, klusterlet *opratorapiv1.
fmt.Sprintf("%s-registration-agent", klusterlet.Name), namespace)
if klusterlet.Spec.RegistrationImagePullSpec != o.Spec.Template.Spec.Containers[0].Image {
t.Errorf("Image does not match to the expected.")
return
}
} else if strings.Contains(access.GetName(), "work") {
testinghelper.AssertEqualNameNamespace(
@@ -374,9 +388,11 @@ func ensureObject(t *testing.T, object runtime.Object, klusterlet *opratorapiv1.
fmt.Sprintf("%s-work-agent", klusterlet.Name), namespace)
if klusterlet.Spec.WorkImagePullSpec != o.Spec.Template.Spec.Containers[0].Image {
t.Errorf("Image does not match to the expected.")
return
}
} else {
t.Errorf("Unexpected deployment")
return
}
}
}
@@ -388,7 +404,7 @@ func TestSyncDeploy(t *testing.T) {
hubKubeConfigSecret := newSecret(helpers.HubKubeConfig, "testns")
hubKubeConfigSecret.Data["kubeconfig"] = []byte("dummuykubeconnfig")
namespace := newNamespace("testns")
controller := newTestController(klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace)
controller := newTestController(t, klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace)
syncContext := testinghelper.NewFakeSyncContext(t, "klusterlet")
err := controller.controller.sync(context.TODO(), syncContext)
@@ -450,7 +466,7 @@ func TestSyncDeployHosted(t *testing.T) {
// externalManagedSecret.Data["kubeconfig"] = []byte("dummuykubeconnfig")
namespace := newNamespace(agentNamespace)
pullSecret := newSecret(imagePullSecret, "open-cluster-management")
controller := newTestControllerHosted(klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace, pullSecret /*externalManagedSecret*/)
controller := newTestControllerHosted(t, klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace, pullSecret /*externalManagedSecret*/)
syncContext := testinghelper.NewFakeSyncContext(t, "klusterlet")
err := controller.controller.sync(context.TODO(), syncContext)
@@ -552,7 +568,7 @@ func TestSyncDelete(t *testing.T) {
newAppliedManifestWorks("testhost", []string{appliedManifestWorkFinalizer}, true),
newAppliedManifestWorks("testhost-2", []string{appliedManifestWorkFinalizer}, false),
}
controller := newTestController(klusterlet, appliedManifestWorks, namespace, bootstrapKubeConfigSecret)
controller := newTestController(t, klusterlet, appliedManifestWorks, namespace, bootstrapKubeConfigSecret)
syncContext := testinghelper.NewFakeSyncContext(t, "klusterlet")
err := controller.controller.sync(context.TODO(), syncContext)
@@ -619,7 +635,7 @@ func TestSyncDeleteHosted(t *testing.T) {
newAppliedManifestWorks("testhost", []string{appliedManifestWorkFinalizer}, true),
newAppliedManifestWorks("testhost-2", []string{appliedManifestWorkFinalizer}, false),
}
controller := newTestControllerHosted(klusterlet, appliedManifestWorks, bootstrapKubeConfigSecret, namespace /*externalManagedSecret*/)
controller := newTestControllerHosted(t, klusterlet, appliedManifestWorks, bootstrapKubeConfigSecret, namespace /*externalManagedSecret*/)
syncContext := testinghelper.NewFakeSyncContext(t, klusterlet.Name)
err := controller.controller.sync(context.TODO(), syncContext)
@@ -741,7 +757,7 @@ func TestReplica(t *testing.T) {
hubSecret,
}
controller := newTestController(klusterlet, nil, objects...)
controller := newTestController(t, klusterlet, nil, objects...)
syncContext := testinghelper.NewFakeSyncContext(t, "klusterlet")
err := controller.controller.sync(context.TODO(), syncContext)
@@ -761,7 +777,9 @@ func TestReplica(t *testing.T) {
},
}
controller.operatorStore.Update(klusterlet)
if err := controller.operatorStore.Update(klusterlet); err != nil {
t.Fatal(err)
}
controller.kubeClient.ClearActions()
controller.operatorClient.ClearActions()
@@ -803,7 +821,7 @@ func TestClusterNameChange(t *testing.T) {
hubSecret := newSecret(helpers.HubKubeConfig, "testns")
hubSecret.Data["kubeconfig"] = []byte("dummuykubeconnfig")
hubSecret.Data["cluster-name"] = []byte("cluster1")
controller := newTestController(klusterlet, nil, bootStrapSecret, hubSecret, namespace)
controller := newTestController(t, klusterlet, nil, bootStrapSecret, hubSecret, namespace)
syncContext := testinghelper.NewFakeSyncContext(t, "klusterlet")
err := controller.controller.sync(context.TODO(), syncContext)
@@ -833,7 +851,9 @@ func TestClusterNameChange(t *testing.T) {
controller.operatorClient.ClearActions()
klusterlet = newKlusterlet("klusterlet", "testns", "")
klusterlet.Generation = 1
controller.operatorStore.Update(klusterlet)
if err := controller.operatorStore.Update(klusterlet); err != nil {
t.Fatal(err)
}
err = controller.controller.sync(context.TODO(), syncContext)
if err != nil {
@@ -869,7 +889,9 @@ func TestClusterNameChange(t *testing.T) {
klusterlet.Spec.ExternalServerURLs = []opratorapiv1.ServerURL{{URL: "https://localhost"}}
controller.kubeClient.ClearActions()
controller.operatorClient.ClearActions()
controller.operatorStore.Update(klusterlet)
if err := controller.operatorStore.Update(klusterlet); err != nil {
t.Fatal(err)
}
err = controller.controller.sync(context.TODO(), syncContext)
if err != nil {
@@ -886,7 +908,7 @@ func TestSyncWithPullSecret(t *testing.T) {
hubKubeConfigSecret.Data["kubeconfig"] = []byte("dummuykubeconnfig")
namespace := newNamespace("testns")
pullSecret := newSecret(imagePullSecret, "open-cluster-management")
controller := newTestController(klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace, pullSecret)
controller := newTestController(t, klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace, pullSecret)
syncContext := testinghelper.NewFakeSyncContext(t, "klusterlet")
err := controller.controller.sync(context.TODO(), syncContext)
@@ -915,7 +937,7 @@ func TestDeployOnKube111(t *testing.T) {
hubKubeConfigSecret := newSecret(helpers.HubKubeConfig, "testns")
hubKubeConfigSecret.Data["kubeconfig"] = []byte("dummuykubeconnfig")
namespace := newNamespace("testns")
controller := newTestController(klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace)
controller := newTestController(t, klusterlet, nil, bootStrapSecret, hubKubeConfigSecret, namespace)
kubeVersion, _ := version.ParseGeneric("v1.11.0")
controller.controller.kubeVersion = kubeVersion
syncContext := testinghelper.NewFakeSyncContext(t, "klusterlet")
@@ -970,7 +992,9 @@ func TestDeployOnKube111(t *testing.T) {
// Delete the klusterlet
now := metav1.Now()
klusterlet.ObjectMeta.SetDeletionTimestamp(&now)
controller.operatorStore.Update(klusterlet)
if err := controller.operatorStore.Update(klusterlet); err != nil {
t.Fatal(err)
}
controller.kubeClient.ClearActions()
err = controller.controller.sync(ctx, syncContext)
if err != nil {
@@ -43,11 +43,7 @@ type klusterletLocker struct {
}
const (
bootstrapSecret = "BootstrapSecret"
bootstrapSecretDegraded = "BootstrapSecretDegraded"
hubConfigSecret = "HubConfigSecret"
hubConfigSecretDegraded = "HubConfigSecretDegraded"
hubConnectionDegraded = "HubConnectionDegraded"
hubConnectionDegraded = "HubConnectionDegraded"
)
func NewKlusterletSSARController(
@@ -82,7 +82,7 @@ func newKlusterlet(name, namespace, clustername string) *operatorapiv1.Klusterle
}
}
func newTestController(klusterlet *operatorapiv1.Klusterlet, objects ...runtime.Object) *testController {
func newTestController(t *testing.T, klusterlet *operatorapiv1.Klusterlet, objects ...runtime.Object) *testController {
fakeKubeClient := fakekube.NewSimpleClientset(objects...)
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(klusterlet)
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
@@ -99,7 +99,9 @@ func newTestController(klusterlet *operatorapiv1.Klusterlet, objects ...runtime.
}
store := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
store.Add(klusterlet)
if err := store.Add(klusterlet); err != nil {
t.Fatal(err)
}
return &testController{
controller: klusterletController,
@@ -121,7 +123,9 @@ func TestSync(t *testing.T) {
return
}
ssar := &authorizationv1.SelfSubjectAccessReview{}
json.Unmarshal(data, ssar)
if err := json.Unmarshal(data, ssar); err != nil {
t.Fatal(err)
}
if ssar.Spec.ResourceAttributes.Resource == "managedclusters" {
if ssar.Spec.ResourceAttributes.Subresource == "status" {
ssar.Status.Allowed = response.allowToOperateManagedClusterStatus
@@ -136,7 +140,9 @@ func TestSync(t *testing.T) {
w.Header().Set("Content-type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(ssar)
if err := json.NewEncoder(w).Encode(ssar); err != nil {
t.Fatal(err)
}
}))
defer apiServer.Close()
@@ -237,7 +243,7 @@ func TestSync(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
controller := newTestController(c.klusterlet, c.object...)
controller := newTestController(t, c.klusterlet, c.object...)
syncContext := testinghelper.NewFakeSyncContext(t, c.klusterlet.Name)
response.allowToOperateManagedClusters = c.allowToOperateManagedClusters
@@ -53,7 +53,7 @@ func newDeployment(name, namespace string, desiredReplica, availableReplica int3
}
}
func newTestController(klusterlet *operatorapiv1.Klusterlet, objects ...runtime.Object) *testController {
func newTestController(t *testing.T, klusterlet *operatorapiv1.Klusterlet, objects ...runtime.Object) *testController {
fakeKubeClient := fakekube.NewSimpleClientset(objects...)
fakeOperatorClient := fakeoperatorclient.NewSimpleClientset(klusterlet)
operatorInformers := operatorinformers.NewSharedInformerFactory(fakeOperatorClient, 5*time.Minute)
@@ -67,7 +67,9 @@ func newTestController(klusterlet *operatorapiv1.Klusterlet, objects ...runtime.
}
store := operatorInformers.Operator().V1().Klusterlets().Informer().GetStore()
store.Add(klusterlet)
if err := store.Add(klusterlet); err != nil {
t.Fatal(err)
}
return &testController{
controller: klusterletController,
@@ -153,7 +155,7 @@ func TestSync(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
controller := newTestController(c.klusterlet, c.object...)
controller := newTestController(t, c.klusterlet, c.object...)
syncContext := testinghelper.NewFakeSyncContext(t, c.klusterlet.Name)
err := controller.controller.sync(context.TODO(), syncContext)
+1 -1
View File
@@ -21,7 +21,7 @@ var _ = Describe("Manage the managed cluster addons", func() {
})
AfterEach(func() {
By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName))
t.cleanKlusterletResources(klusterletName, clusterName)
Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil())
})
It("Create one managed cluster addon and make sure it is available", func() {
+1 -1
View File
@@ -26,7 +26,7 @@ var _ = Describe("Create klusterlet CR", func() {
AfterEach(func() {
By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName))
t.cleanKlusterletResources(klusterletName, clusterName)
Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil())
})
// This test case is helpful for the Backward compatibility
+1 -1
View File
@@ -27,7 +27,7 @@ var _ = Describe("Create klusterlet and then create a configmap by manifestwork"
AfterEach(func() {
By(fmt.Sprintf("clean klusterlet %s resources after the test case, clusterName: %s", klusterletName, clusterName))
t.cleanKlusterletResources(klusterletName, clusterName)
Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil())
})
It("Create configmap using manifestwork and then delete klusterlet", func() {
@@ -38,7 +38,6 @@ const (
eventuallyTimeout = 30 // seconds
eventuallyInterval = 1 // seconds
hubNamespace = "open-cluster-management-hub"
spokeNamespace = "open-cluster-management-agent"
clusterManagerName = "hub"
hubNamespaceHosted = "hub"
)
+1 -1
View File
@@ -98,7 +98,7 @@ var _ = ginkgo.Describe("Klusterlet Hosted mode", func() {
})
ginkgo.AfterEach(func() {
operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})
gomega.Expect(operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})).To(gomega.BeNil())
})
ginkgo.It("should have expected resource created successfully", func() {
+3 -3
View File
@@ -112,7 +112,7 @@ var _ = ginkgo.Describe("Klusterlet", func() {
})
ginkgo.AfterEach(func() {
operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})
gomega.Expect(operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})).To(gomega.BeNil())
})
ginkgo.It("should have expected resource created successfully", func() {
@@ -584,7 +584,7 @@ var _ = ginkgo.Describe("Klusterlet", func() {
workDeploymentName = fmt.Sprintf("%s-work-agent", klusterlet.Name)
})
ginkgo.AfterEach(func() {
operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})
gomega.Expect(operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})).To(gomega.BeNil())
})
ginkgo.It("should have correct degraded conditions", func() {
_, err := operatorClient.OperatorV1().Klusterlets().Create(context.Background(), klusterlet, metav1.CreateOptions{})
@@ -701,7 +701,7 @@ var _ = ginkgo.Describe("Klusterlet", func() {
workDeploymentName = fmt.Sprintf("%s-work-agent", klusterlet.Name)
})
ginkgo.AfterEach(func() {
operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})
gomega.Expect(operatorClient.OperatorV1().Klusterlets().Delete(context.Background(), klusterlet.Name, metav1.DeleteOptions{})).To(gomega.BeNil())
})
ginkgo.It("should reload the klusterlet after the bootstrap secret is changed", func() {
+1 -3
View File
@@ -65,12 +65,10 @@ func (r *IntegrationTestEventRecorder) Warningf(reason, messageFmt string, args
func (r *IntegrationTestEventRecorder) Shutdown() {}
func HasCondition(conditions []metav1.Condition, expectedType, expectedReason string, expectedStatus metav1.ConditionStatus) bool {
found := false
for _, condition := range conditions {
if condition.Type != expectedType {
continue
}
found = true
if condition.Status != expectedStatus {
return false
@@ -83,7 +81,7 @@ func HasCondition(conditions []metav1.Condition, expectedType, expectedReason st
return true
}
return found
return false
}
func NewKubeConfig(config *rest.Config) []byte {