From 717c747816c56a5cad320bd6bb1299c9393a9ff7 Mon Sep 17 00:00:00 2001 From: DQ Date: Wed, 16 Apr 2025 17:41:56 +1000 Subject: [PATCH 1/6] feat: add cached requirement feature to integration tests --- test/integration/integration_test.go | 190 ++++++++++++++++++++++++++- test/integration/main_test.go | 2 +- 2 files changed, 188 insertions(+), 4 deletions(-) diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index 0c895db..dc3e0b1 100644 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/stretchr/testify/assert" + apierr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" @@ -18,10 +19,11 @@ import ( type requirementKey struct{} const ( - testRequirementName = "test-requirement" + testRequirementName = "test-requirement" + cachedRequirementName = "cached-requirement" ) -var CacheFeature = features.New("Simple Requirements"). +var SimpleRequirementFeature = features.New("Simple Requirements"). Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { // start a deployment requiremnt := utils.NewRequirement(testRequirementName, utils.TestNamespcae) @@ -33,7 +35,7 @@ var CacheFeature = features.New("Simple Requirements"). return ctx }). - Assess("create requirement", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + Assess("requirement created successfully", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { var requirement v1.Requirement if err := cfg.Client().Resources().Get(ctx, testRequirementName, utils.TestNamespcae, &requirement); err != nil { t.Fatal(err) @@ -60,3 +62,185 @@ var CacheFeature = features.New("Simple Requirements"). } return ctx }).Feature() + +func newRequirementWithCache(name string) *v1.Requirement { + requirement := utils.NewRequirement(name, utils.TestNamespcae) + requirement.Spec.EnableCache = true + return requirement +} + +var CachedRequirementFeature = features.New("Cached Requirements"). + Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { + // Create a requirement with cache enabled + if err := c.Client().Resources().Create(ctx, newRequirementWithCache(cachedRequirementName)); err != nil { + t.Fatal(err) + } + time.Sleep(2 * time.Second) + return ctx + }). + Assess("cache requirement created and synced", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + var requirement v1.Requirement + if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespcae, &requirement); err != nil { + t.Fatal(err) + } + assert.Equal(t, cachedRequirementName, requirement.Name) + + // Wait for requirement to be ready + if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { + requirement := &v1.Requirement{} + if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespcae, requirement); err != nil { + return false, err + } + if requirement.Status.Phase != rqutils.PhaseReady { + return false, nil + } + return true, nil + }); err != nil { + t.Fatal(err, "requirement not ready") + } + cacheKey := requirement.Status.CacheKey + // Get the associated Cache resource + cache := &v1.Cache{} + cacheName := "cache-" + cacheKey + if err := cfg.Client().Resources().Get(ctx, cacheName, utils.TestNamespcae, cache); err != nil { + t.Fatal(err, "cache not found") + } + // Verify the cache key matches + assert.Equal(t, cacheKey, cache.Status.CacheKey) + + // Get all Operations + var operations v1.OperationList + if err := cfg.Client().Resources().List(ctx, &operations); err != nil { + t.Fatal(err, "failed to list operations") + } + + // Verify one operation is owned by our requirement by checking owner references + var ( + ownedByRequirement []v1.Operation + ownedByCache []v1.Operation + ) + for _, op := range operations.Items { + for _, ownerRef := range op.OwnerReferences { + if ownerRef.APIVersion == v1.GroupVersion.String() && + ownerRef.Kind == "Requirement" && + ownerRef.Name == requirement.Name && + ownerRef.UID == requirement.UID { + ownedByRequirement = append(ownedByRequirement, op) + } + if ownerRef.APIVersion == v1.GroupVersion.String() && + ownerRef.Kind == "Cache" && + ownerRef.Name == cache.Name && + ownerRef.UID == cache.UID { + ownedByCache = append(ownedByCache, op) + } + } + } + // Verify one operation is owned by our requirement + assert.Equal(t, 1, len(ownedByRequirement), "expected one operation owned by requirement") + // Verify number of cache operations matches keepAlive count + assert.Equal(t, int(cache.Status.KeepAliveCount), len(ownedByCache)) + + // delete the requirement + if err := cfg.Client().Resources().Delete(ctx, &requirement); err != nil { + t.Fatal(err) + } + // wait for the requirement to be deleted + if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { + requirement := &v1.Requirement{} + err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespcae, requirement) + // err is not found, so requirement is deleted + if err != nil { + if apierr.IsNotFound(err) { + return true, nil + } + return false, err + } + return false, nil + }); err != nil { + t.Fatal(err, "requirement not deleted") + } + + newCachedRequirementName := cachedRequirementName + "-new" + // create a new requirement with the same name + if err := cfg.Client().Resources().Create(ctx, newRequirementWithCache(newCachedRequirementName)); err != nil { + t.Fatal(err) + } + + newRequirement := &v1.Requirement{} + // wait for the new requirement to be ready + if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { + if err := cfg.Client().Resources().Get(ctx, newCachedRequirementName, utils.TestNamespcae, newRequirement); err != nil { + return false, err + } + if newRequirement.Status.Phase != rqutils.PhaseReady { + return false, nil + } + return true, nil + }); err != nil { + t.Fatal(err, "new requirement not ready") + } + + // cache should be hit + cacheHit := false + for _, condition := range newRequirement.Status.Conditions { + if condition.Type == rqutils.ConditionOperationReady { + cacheHit = true + break + } + } + assert.True(t, cacheHit, "expected cache hit condition") + + // list operations and verify the new requirement has operation with the same name from original cache + var newOperations v1.OperationList + if err := cfg.Client().Resources().List(ctx, &newOperations); err != nil { + t.Fatal(err, "failed to list operations") + } + var ( + ownedByNewRequirement []v1.Operation + ownedByCurrentCache []v1.Operation + ) + + for _, op := range newOperations.Items { + for _, ownerRef := range op.OwnerReferences { + if ownerRef.APIVersion == v1.GroupVersion.String() && + ownerRef.Kind == "Requirement" && + ownerRef.Name == newCachedRequirementName && + ownerRef.UID == newRequirement.UID { + ownedByNewRequirement = append(ownedByNewRequirement, op) + } + if ownerRef.APIVersion == v1.GroupVersion.String() && + ownerRef.Kind == "Cache" && + ownerRef.Name == cacheName && + ownerRef.UID == cache.UID { + ownedByCurrentCache = append(ownedByCurrentCache, op) + } + } + } + // Verify one operation is owned by our requirement + assert.Equal(t, 1, len(ownedByNewRequirement), "expected one operation owned by requirement") + // Verify number of cache operations matches keepAlive count + assert.Equal(t, int(cache.Status.KeepAliveCount), len(ownedByCurrentCache)) + + // Verify the operation come from the original cache + found := false + for _, op := range ownedByCache { + if op.Name == ownedByNewRequirement[0].Name { + found = true + break + } + } + assert.True(t, found, "expected operation to be from original cache") + + // the operation should not be included in the new cache + for _, op := range ownedByCurrentCache { + assert.NotEqual(t, op.Name, ownedByNewRequirement[0].Name, "operation should not be included in the new cache") + } + return context.WithValue(ctx, requirementKey{}, newRequirement) + }). + Teardown(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { + requirement := ctx.Value(requirementKey{}).(*v1.Requirement) + if err := cfg.Client().Resources().Delete(ctx, requirement); err != nil { + t.Fatal(err) + } + return ctx + }).Feature() diff --git a/test/integration/main_test.go b/test/integration/main_test.go index 5a1d799..94a8f72 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -86,5 +86,5 @@ func UninstallCRD(ctx context.Context, cfg *envconf.Config) (context.Context, er func TestRealCluster(t *testing.T) { // Create a new test environment configuration // Run the integration tests against the Kind cluster - testenv.Test(t, CacheFeature) + testenv.Test(t, SimpleRequirementFeature, CachedRequirementFeature) } From 362e101fa9235f738627d9feaf14e284e9cfd220 Mon Sep 17 00:00:00 2001 From: DQ Date: Wed, 16 Apr 2025 17:45:15 +1000 Subject: [PATCH 2/6] fix: correct typo in TestNamespace constant --- test/utils/resources.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils/resources.go b/test/utils/resources.go index e6abe1c..82217c8 100644 --- a/test/utils/resources.go +++ b/test/utils/resources.go @@ -8,7 +8,7 @@ import ( ) const ( - TestNamespcae = "operation-cache-controller-system" + TestNamespace = "operation-cache-controller-system" ) func NewTestJobSpec(name string) batchv1.JobSpec { From 214eb77da7cba4fe457ee4180da3bb5270efb41c Mon Sep 17 00:00:00 2001 From: DQ Date: Wed, 16 Apr 2025 17:48:39 +1000 Subject: [PATCH 3/6] fix: correct namespace references in integration tests --- test/integration/integration_test.go | 22 +++++++++++----------- test/integration/main_test.go | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index dc3e0b1..2cdbac7 100644 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -26,9 +26,9 @@ const ( var SimpleRequirementFeature = features.New("Simple Requirements"). Setup(func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { // start a deployment - requiremnt := utils.NewRequirement(testRequirementName, utils.TestNamespcae) - requiremnt.Namespace = utils.TestNamespcae - if err := c.Client().Resources().Create(ctx, requiremnt); err != nil { + testRequirement := utils.NewRequirement(testRequirementName, utils.TestNamespace) + testRequirement.Namespace = utils.TestNamespace + if err := c.Client().Resources().Create(ctx, testRequirement); err != nil { t.Fatal(err) } time.Sleep(2 * time.Second) @@ -37,13 +37,13 @@ var SimpleRequirementFeature = features.New("Simple Requirements"). }). Assess("requirement created successfully", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { var requirement v1.Requirement - if err := cfg.Client().Resources().Get(ctx, testRequirementName, utils.TestNamespcae, &requirement); err != nil { + if err := cfg.Client().Resources().Get(ctx, testRequirementName, utils.TestNamespace, &requirement); err != nil { t.Fatal(err) } assert.Equal(t, testRequirementName, requirement.Name) if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { requirement := &v1.Requirement{} - if err := cfg.Client().Resources().Get(ctx, testRequirementName, utils.TestNamespcae, requirement); err != nil { + if err := cfg.Client().Resources().Get(ctx, testRequirementName, utils.TestNamespace, requirement); err != nil { return false, err } if requirement.Status.Phase != rqutils.PhaseReady { @@ -64,7 +64,7 @@ var SimpleRequirementFeature = features.New("Simple Requirements"). }).Feature() func newRequirementWithCache(name string) *v1.Requirement { - requirement := utils.NewRequirement(name, utils.TestNamespcae) + requirement := utils.NewRequirement(name, utils.TestNamespace) requirement.Spec.EnableCache = true return requirement } @@ -80,7 +80,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). }). Assess("cache requirement created and synced", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { var requirement v1.Requirement - if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespcae, &requirement); err != nil { + if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespace, &requirement); err != nil { t.Fatal(err) } assert.Equal(t, cachedRequirementName, requirement.Name) @@ -88,7 +88,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). // Wait for requirement to be ready if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { requirement := &v1.Requirement{} - if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespcae, requirement); err != nil { + if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespace, requirement); err != nil { return false, err } if requirement.Status.Phase != rqutils.PhaseReady { @@ -102,7 +102,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). // Get the associated Cache resource cache := &v1.Cache{} cacheName := "cache-" + cacheKey - if err := cfg.Client().Resources().Get(ctx, cacheName, utils.TestNamespcae, cache); err != nil { + if err := cfg.Client().Resources().Get(ctx, cacheName, utils.TestNamespace, cache); err != nil { t.Fatal(err, "cache not found") } // Verify the cache key matches @@ -147,7 +147,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). // wait for the requirement to be deleted if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { requirement := &v1.Requirement{} - err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespcae, requirement) + err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespace, requirement) // err is not found, so requirement is deleted if err != nil { if apierr.IsNotFound(err) { @@ -169,7 +169,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). newRequirement := &v1.Requirement{} // wait for the new requirement to be ready if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { - if err := cfg.Client().Resources().Get(ctx, newCachedRequirementName, utils.TestNamespcae, newRequirement); err != nil { + if err := cfg.Client().Resources().Get(ctx, newCachedRequirementName, utils.TestNamespace, newRequirement); err != nil { return false, err } if newRequirement.Status.Phase != rqutils.PhaseReady { diff --git a/test/integration/main_test.go b/test/integration/main_test.go index 94a8f72..ca20f70 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -41,14 +41,14 @@ func TestMain(m *testing.M) { BuildImage, envfuncs.CreateCluster(kind.NewProvider(), kindClusterName), envfuncs.LoadDockerImageToCluster(kindClusterName, projectImage), - envfuncs.CreateNamespace(utils.TestNamespcae), + envfuncs.CreateNamespace(utils.TestNamespace), InstallCRD, DeployControllerManager, ) // Teardown the test environment testenv = testenv.Finish( - envfuncs.DeleteNamespace(utils.TestNamespcae), + envfuncs.DeleteNamespace(utils.TestNamespace), envfuncs.DestroyCluster(kindClusterName), ) From dce198e8191efc1da1f1dae8ffae916a46a36256 Mon Sep 17 00:00:00 2001 From: DQ Date: Thu, 17 Apr 2025 13:27:23 +1000 Subject: [PATCH 4/6] Refactor API version from v1 to v1alpha1 across the application - Updated import paths to use v1alpha1 instead of v1 in multiple files. - Modified function signatures and types to reflect the new API version. - Adjusted test cases to accommodate changes in the API version. - Ensured consistency in the usage of the new API version throughout the codebase. --- .github/.testcoverage.yml | 2 +- PROJECT | 4 +- api/{v1 => v1alpha1}/appdeployment_types.go | 2 +- api/{v1 => v1alpha1}/cache_types.go | 2 +- api/{v1 => v1alpha1}/groupversion_info.go | 8 +- api/{v1 => v1alpha1}/operation_types.go | 2 +- api/{v1 => v1alpha1}/requirement_types.go | 2 +- api/{v1 => v1alpha1}/zz_generated.deepcopy.go | 10 +- cmd/main.go | 4 +- ...ller.azure.github.com_appdeployments.yaml} | 6 +- ...> controller.azure.github.com_caches.yaml} | 6 +- ...ntroller.azure.github.com_operations.yaml} | 6 +- ...roller.azure.github.com_requirements.yaml} | 6 +- config/crd/kustomization.yaml | 8 +- config/rbac/appdeployment_admin_role.yaml | 6 +- config/rbac/appdeployment_editor_role.yaml | 6 +- config/rbac/appdeployment_viewer_role.yaml | 6 +- config/rbac/cache_admin_role.yaml | 6 +- config/rbac/cache_editor_role.yaml | 6 +- config/rbac/cache_viewer_role.yaml | 6 +- config/rbac/operation_admin_role.yaml | 6 +- config/rbac/operation_editor_role.yaml | 6 +- config/rbac/operation_viewer_role.yaml | 6 +- config/rbac/requirement_admin_role.yaml | 6 +- config/rbac/requirement_editor_role.yaml | 6 +- config/rbac/requirement_viewer_role.yaml | 6 +- config/rbac/role.yaml | 42 +++---- ...t.yaml => app_v1alpha1_appdeployment.yaml} | 2 +- ..._v1_cache.yaml => app_v1alpha1_cache.yaml} | 2 +- ...ation.yaml => app_v1alpha1_operation.yaml} | 2 +- ...ent.yaml => app_v1alpha1_requirement.yaml} | 2 +- internal/controller/appdeployment_adapter.go | 8 +- .../controller/appdeployment_adapter_test.go | 34 +++--- .../controller/appdeployment_controller.go | 14 +-- .../appdeployment_controller_test.go | 12 +- internal/controller/cache_adapter.go | 22 ++-- internal/controller/cache_adapter_test.go | 92 +++++++-------- internal/controller/cache_controller.go | 24 ++-- internal/controller/cache_controller_test.go | 31 +++-- internal/controller/operation_adapter.go | 24 ++-- internal/controller/operation_adapter_test.go | 48 ++++---- internal/controller/operation_controller.go | 20 ++-- .../controller/operation_controller_test.go | 23 ++-- internal/controller/requirement_adapter.go | 20 ++-- .../controller/requirement_adapter_test.go | 70 +++++------ internal/controller/requirement_controller.go | 20 ++-- .../controller/requirement_controller_test.go | 24 ++-- internal/controller/suite_test.go | 4 +- .../controller/appdeployment/conditions.go | 2 +- .../appdeployment/conditions_test.go | 2 +- .../utils/controller/appdeployment/job.go | 12 +- .../controller/appdeployment/job_test.go | 2 +- .../controller/appdeployment/validate.go | 10 +- .../controller/appdeployment/validate_test.go | 110 +++++++++--------- internal/utils/controller/cache/cache.go | 4 +- internal/utils/controller/cache/cache_test.go | 6 +- internal/utils/controller/cachekey.go | 10 +- internal/utils/controller/cachekey_test.go | 12 +- .../utils/controller/operation/operation.go | 10 +- .../controller/operation/operation_test.go | 38 +++--- internal/utils/controller/operation/status.go | 4 +- .../utils/controller/operation/status_test.go | 4 +- .../utils/controller/requirement/status.go | 10 +- .../controller/requirement/status_test.go | 16 +-- test/integration/integration_test.go | 42 +++---- test/integration/main_test.go | 4 +- test/utils/resources.go | 23 ++-- 67 files changed, 500 insertions(+), 501 deletions(-) rename api/{v1 => v1alpha1}/appdeployment_types.go (99%) rename api/{v1 => v1alpha1}/cache_types.go (99%) rename api/{v1 => v1alpha1}/groupversion_info.go (80%) rename api/{v1 => v1alpha1}/operation_types.go (99%) rename api/{v1 => v1alpha1}/requirement_types.go (99%) rename api/{v1 => v1alpha1}/zz_generated.deepcopy.go (98%) rename config/crd/bases/{app.github.com_appdeployments.yaml => controller.azure.github.com_appdeployments.yaml} (99%) rename config/crd/bases/{app.github.com_caches.yaml => controller.azure.github.com_caches.yaml} (99%) rename config/crd/bases/{app.github.com_operations.yaml => controller.azure.github.com_operations.yaml} (99%) rename config/crd/bases/{app.github.com_requirements.yaml => controller.azure.github.com_requirements.yaml} (99%) rename config/samples/{app_v1_appdeployment.yaml => app_v1alpha1_appdeployment.yaml} (80%) rename config/samples/{app_v1_cache.yaml => app_v1alpha1_cache.yaml} (79%) rename config/samples/{app_v1_operation.yaml => app_v1alpha1_operation.yaml} (80%) rename config/samples/{app_v1_requirement.yaml => app_v1alpha1_requirement.yaml} (80%) diff --git a/.github/.testcoverage.yml b/.github/.testcoverage.yml index fc291ce..530fcc3 100644 --- a/.github/.testcoverage.yml +++ b/.github/.testcoverage.yml @@ -39,7 +39,7 @@ exclude: # Exclude files or packages matching their paths paths: - .*mock.* # excludes all generated mock files - - ^api/v1 # exclude api/v1 + - ^api/v1alpha1 # exclude api/v1alpha1 - ^test/ # exclude test files - ^cmd # exclude cmd files diff --git a/PROJECT b/PROJECT index e61e48c..f6b289f 100644 --- a/PROJECT +++ b/PROJECT @@ -15,6 +15,6 @@ resources: domain: github.com group: app kind: AppDeployment - path: github.com/Azure/operation-cache-controller/api/v1 - version: v1 + path: github.com/Azure/operation-cache-controller/api/v1alpha1 + version: v1alpha1 version: "3" diff --git a/api/v1/appdeployment_types.go b/api/v1alpha1/appdeployment_types.go similarity index 99% rename from api/v1/appdeployment_types.go rename to api/v1alpha1/appdeployment_types.go index 16c2d38..e17f9d4 100644 --- a/api/v1/appdeployment_types.go +++ b/api/v1alpha1/appdeployment_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1alpha1 import ( batchv1 "k8s.io/api/batch/v1" diff --git a/api/v1/cache_types.go b/api/v1alpha1/cache_types.go similarity index 99% rename from api/v1/cache_types.go rename to api/v1alpha1/cache_types.go index 0d46e77..10fa978 100644 --- a/api/v1/cache_types.go +++ b/api/v1alpha1/cache_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/api/v1/groupversion_info.go b/api/v1alpha1/groupversion_info.go similarity index 80% rename from api/v1/groupversion_info.go rename to api/v1alpha1/groupversion_info.go index 675e485..f737703 100644 --- a/api/v1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package v1 contains API Schema definitions for the app v1 API group. +// Package v1alpha1 contains API Schema definitions for the app v1alpha1 API group. // +kubebuilder:object:generate=true -// +groupName=app.github.com -package v1 +// +groupName=controller.azure.github.com +package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime/schema" @@ -26,7 +26,7 @@ import ( var ( // GroupVersion is group version used to register these objects. - GroupVersion = schema.GroupVersion{Group: "app.github.com", Version: "v1"} + GroupVersion = schema.GroupVersion{Group: "controller.azure.github.com", Version: "v1alpha1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme. SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} diff --git a/api/v1/operation_types.go b/api/v1alpha1/operation_types.go similarity index 99% rename from api/v1/operation_types.go rename to api/v1alpha1/operation_types.go index 133df65..ba849ef 100644 --- a/api/v1/operation_types.go +++ b/api/v1alpha1/operation_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1alpha1 import ( batchv1 "k8s.io/api/batch/v1" diff --git a/api/v1/requirement_types.go b/api/v1alpha1/requirement_types.go similarity index 99% rename from api/v1/requirement_types.go rename to api/v1alpha1/requirement_types.go index eb5a8d0..1fd6465 100644 --- a/api/v1/requirement_types.go +++ b/api/v1alpha1/requirement_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package v1alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go similarity index 98% rename from api/v1/zz_generated.deepcopy.go rename to api/v1alpha1/zz_generated.deepcopy.go index b4e789c..286099d 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -18,10 +18,10 @@ limitations under the License. // Code generated by controller-gen. DO NOT EDIT. -package v1 +package v1alpha1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -111,7 +111,7 @@ func (in *AppDeploymentStatus) DeepCopyInto(out *AppDeploymentStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]metav1.Condition, len(*in)) + *out = make([]v1.Condition, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -331,7 +331,7 @@ func (in *OperationStatus) DeepCopyInto(out *OperationStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]metav1.Condition, len(*in)) + *out = make([]v1.Condition, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -428,7 +428,7 @@ func (in *RequirementStatus) DeepCopyInto(out *RequirementStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions - *out = make([]metav1.Condition, len(*in)) + *out = make([]v1.Condition, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } diff --git a/cmd/main.go b/cmd/main.go index 1f35c2c..9d6cffb 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -37,7 +37,7 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/controller" // +kubebuilder:scaffold:imports ) @@ -50,7 +50,7 @@ var ( func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(appv1.AddToScheme(scheme)) + utilruntime.Must(v1alpha1.AddToScheme(scheme)) // +kubebuilder:scaffold:scheme } diff --git a/config/crd/bases/app.github.com_appdeployments.yaml b/config/crd/bases/controller.azure.github.com_appdeployments.yaml similarity index 99% rename from config/crd/bases/app.github.com_appdeployments.yaml rename to config/crd/bases/controller.azure.github.com_appdeployments.yaml index 9875d4a..24445ec 100644 --- a/config/crd/bases/app.github.com_appdeployments.yaml +++ b/config/crd/bases/controller.azure.github.com_appdeployments.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.17.2 - name: appdeployments.app.github.com + name: appdeployments.controller.azure.github.com spec: - group: app.github.com + group: controller.azure.github.com names: kind: AppDeployment listKind: AppDeploymentList @@ -21,7 +21,7 @@ spec: - jsonPath: .metadata.ownerReferences[0].name name: Owner type: string - name: v1 + name: v1alpha1 schema: openAPIV3Schema: properties: diff --git a/config/crd/bases/app.github.com_caches.yaml b/config/crd/bases/controller.azure.github.com_caches.yaml similarity index 99% rename from config/crd/bases/app.github.com_caches.yaml rename to config/crd/bases/controller.azure.github.com_caches.yaml index e5b6525..a03cd64 100644 --- a/config/crd/bases/app.github.com_caches.yaml +++ b/config/crd/bases/controller.azure.github.com_caches.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.17.2 - name: caches.app.github.com + name: caches.controller.azure.github.com spec: - group: app.github.com + group: controller.azure.github.com names: kind: Cache listKind: CacheList @@ -14,7 +14,7 @@ spec: singular: cache scope: Namespaced versions: - - name: v1 + - name: v1alpha1 schema: openAPIV3Schema: properties: diff --git a/config/crd/bases/app.github.com_operations.yaml b/config/crd/bases/controller.azure.github.com_operations.yaml similarity index 99% rename from config/crd/bases/app.github.com_operations.yaml rename to config/crd/bases/controller.azure.github.com_operations.yaml index 655e06e..8af64be 100644 --- a/config/crd/bases/app.github.com_operations.yaml +++ b/config/crd/bases/controller.azure.github.com_operations.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.17.2 - name: operations.app.github.com + name: operations.controller.azure.github.com spec: - group: app.github.com + group: controller.azure.github.com names: kind: Operation listKind: OperationList @@ -21,7 +21,7 @@ spec: - jsonPath: .status.cacheKey name: Key type: string - name: v1 + name: v1alpha1 schema: openAPIV3Schema: properties: diff --git a/config/crd/bases/app.github.com_requirements.yaml b/config/crd/bases/controller.azure.github.com_requirements.yaml similarity index 99% rename from config/crd/bases/app.github.com_requirements.yaml rename to config/crd/bases/controller.azure.github.com_requirements.yaml index 6f932f4..e15de9d 100644 --- a/config/crd/bases/app.github.com_requirements.yaml +++ b/config/crd/bases/controller.azure.github.com_requirements.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.17.2 - name: requirements.app.github.com + name: requirements.controller.azure.github.com spec: - group: app.github.com + group: controller.azure.github.com names: kind: Requirement listKind: RequirementList @@ -21,7 +21,7 @@ spec: - jsonPath: .status.operationId name: OperationId type: string - name: v1 + name: v1alpha1 schema: openAPIV3Schema: properties: diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 467a92c..afe3274 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -2,10 +2,10 @@ # since it depends on service name and namespace that are out of this kustomize package. # It should be run by config/default resources: -- bases/app.github.com_appdeployments.yaml -- bases/app.github.com_operations.yaml -- bases/app.github.com_caches.yaml -- bases/app.github.com_requirements.yaml +- bases/controller.azure.github.com_appdeployments.yaml +- bases/controller.azure.github.com_operations.yaml +- bases/controller.azure.github.com_caches.yaml +- bases/controller.azure.github.com_requirements.yaml # +kubebuilder:scaffold:crdkustomizeresource patches: diff --git a/config/rbac/appdeployment_admin_role.yaml b/config/rbac/appdeployment_admin_role.yaml index 80a5a20..a3dd13e 100644 --- a/config/rbac/appdeployment_admin_role.yaml +++ b/config/rbac/appdeployment_admin_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants full permissions ('*') over app.github.com. +# Grants full permissions ('*') over controller.azure.github.com. # This role is intended for users authorized to modify roles and bindings within the cluster, # enabling them to delegate specific permissions to other users or groups as needed. @@ -14,13 +14,13 @@ metadata: name: appdeployment-admin-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - appdeployments verbs: - '*' - apiGroups: - - app.github.com + - controller.azure.github.com resources: - appdeployments/status verbs: diff --git a/config/rbac/appdeployment_editor_role.yaml b/config/rbac/appdeployment_editor_role.yaml index 1de1009..5c4bb2f 100644 --- a/config/rbac/appdeployment_editor_role.yaml +++ b/config/rbac/appdeployment_editor_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants permissions to create, update, and delete resources within the app.github.com. +# Grants permissions to create, update, and delete resources within the controller.azure.github.com. # This role is intended for users who need to manage these resources # but should not control RBAC or manage permissions for others. @@ -14,7 +14,7 @@ metadata: name: appdeployment-editor-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - appdeployments verbs: @@ -26,7 +26,7 @@ rules: - update - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - appdeployments/status verbs: diff --git a/config/rbac/appdeployment_viewer_role.yaml b/config/rbac/appdeployment_viewer_role.yaml index d97659d..fe1c71f 100644 --- a/config/rbac/appdeployment_viewer_role.yaml +++ b/config/rbac/appdeployment_viewer_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants read-only access to app.github.com resources. +# Grants read-only access to controller.azure.github.com resources. # This role is intended for users who need visibility into these resources # without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. @@ -14,7 +14,7 @@ metadata: name: appdeployment-viewer-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - appdeployments verbs: @@ -22,7 +22,7 @@ rules: - list - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - appdeployments/status verbs: diff --git a/config/rbac/cache_admin_role.yaml b/config/rbac/cache_admin_role.yaml index d257c5d..09c561c 100644 --- a/config/rbac/cache_admin_role.yaml +++ b/config/rbac/cache_admin_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants full permissions ('*') over app.github.com. +# Grants full permissions ('*') over controller.azure.github.com. # This role is intended for users authorized to modify roles and bindings within the cluster, # enabling them to delegate specific permissions to other users or groups as needed. @@ -14,13 +14,13 @@ metadata: name: cache-admin-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - caches verbs: - '*' - apiGroups: - - app.github.com + - controller.azure.github.com resources: - caches/status verbs: diff --git a/config/rbac/cache_editor_role.yaml b/config/rbac/cache_editor_role.yaml index 41bb32d..cf9c88b 100644 --- a/config/rbac/cache_editor_role.yaml +++ b/config/rbac/cache_editor_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants permissions to create, update, and delete resources within the app.github.com. +# Grants permissions to create, update, and delete resources within the controller.azure.github.com. # This role is intended for users who need to manage these resources # but should not control RBAC or manage permissions for others. @@ -14,7 +14,7 @@ metadata: name: cache-editor-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - caches verbs: @@ -26,7 +26,7 @@ rules: - update - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - caches/status verbs: diff --git a/config/rbac/cache_viewer_role.yaml b/config/rbac/cache_viewer_role.yaml index 2a28666..2690961 100644 --- a/config/rbac/cache_viewer_role.yaml +++ b/config/rbac/cache_viewer_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants read-only access to app.github.com resources. +# Grants read-only access to controller.azure.github.com resources. # This role is intended for users who need visibility into these resources # without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. @@ -14,7 +14,7 @@ metadata: name: cache-viewer-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - caches verbs: @@ -22,7 +22,7 @@ rules: - list - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - caches/status verbs: diff --git a/config/rbac/operation_admin_role.yaml b/config/rbac/operation_admin_role.yaml index 03588ec..4073bd5 100644 --- a/config/rbac/operation_admin_role.yaml +++ b/config/rbac/operation_admin_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants full permissions ('*') over app.github.com. +# Grants full permissions ('*') over controller.azure.github.com. # This role is intended for users authorized to modify roles and bindings within the cluster, # enabling them to delegate specific permissions to other users or groups as needed. @@ -14,13 +14,13 @@ metadata: name: operation-admin-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - operations verbs: - '*' - apiGroups: - - app.github.com + - controller.azure.github.com resources: - operations/status verbs: diff --git a/config/rbac/operation_editor_role.yaml b/config/rbac/operation_editor_role.yaml index fff0d21..59022e5 100644 --- a/config/rbac/operation_editor_role.yaml +++ b/config/rbac/operation_editor_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants permissions to create, update, and delete resources within the app.github.com. +# Grants permissions to create, update, and delete resources within the controller.azure.github.com. # This role is intended for users who need to manage these resources # but should not control RBAC or manage permissions for others. @@ -14,7 +14,7 @@ metadata: name: operation-editor-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - operations verbs: @@ -26,7 +26,7 @@ rules: - update - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - operations/status verbs: diff --git a/config/rbac/operation_viewer_role.yaml b/config/rbac/operation_viewer_role.yaml index 84a06c2..5e03347 100644 --- a/config/rbac/operation_viewer_role.yaml +++ b/config/rbac/operation_viewer_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants read-only access to app.github.com resources. +# Grants read-only access to controller.azure.github.com resources. # This role is intended for users who need visibility into these resources # without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. @@ -14,7 +14,7 @@ metadata: name: operation-viewer-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - operations verbs: @@ -22,7 +22,7 @@ rules: - list - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - operations/status verbs: diff --git a/config/rbac/requirement_admin_role.yaml b/config/rbac/requirement_admin_role.yaml index c660140..0341338 100644 --- a/config/rbac/requirement_admin_role.yaml +++ b/config/rbac/requirement_admin_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants full permissions ('*') over app.github.com. +# Grants full permissions ('*') over controller.azure.github.com. # This role is intended for users authorized to modify roles and bindings within the cluster, # enabling them to delegate specific permissions to other users or groups as needed. @@ -14,13 +14,13 @@ metadata: name: requirement-admin-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - requirements verbs: - '*' - apiGroups: - - app.github.com + - controller.azure.github.com resources: - requirements/status verbs: diff --git a/config/rbac/requirement_editor_role.yaml b/config/rbac/requirement_editor_role.yaml index 37e132b..e0c22ee 100644 --- a/config/rbac/requirement_editor_role.yaml +++ b/config/rbac/requirement_editor_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants permissions to create, update, and delete resources within the app.github.com. +# Grants permissions to create, update, and delete resources within the controller.azure.github.com. # This role is intended for users who need to manage these resources # but should not control RBAC or manage permissions for others. @@ -14,7 +14,7 @@ metadata: name: requirement-editor-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - requirements verbs: @@ -26,7 +26,7 @@ rules: - update - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - requirements/status verbs: diff --git a/config/rbac/requirement_viewer_role.yaml b/config/rbac/requirement_viewer_role.yaml index 262853e..24643ab 100644 --- a/config/rbac/requirement_viewer_role.yaml +++ b/config/rbac/requirement_viewer_role.yaml @@ -1,7 +1,7 @@ # This rule is not used by the project operation-cache-controller itself. # It is provided to allow the cluster admin to help manage permissions for users. # -# Grants read-only access to app.github.com resources. +# Grants read-only access to controller.azure.github.com resources. # This role is intended for users who need visibility into these resources # without permissions to modify them. It is ideal for monitoring purposes and limited-access viewing. @@ -14,7 +14,7 @@ metadata: name: requirement-viewer-role rules: - apiGroups: - - app.github.com + - controller.azure.github.com resources: - requirements verbs: @@ -22,7 +22,7 @@ rules: - list - watch - apiGroups: - - app.github.com + - controller.azure.github.com resources: - requirements/status verbs: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 6eeca17..14636ae 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -5,12 +5,9 @@ metadata: name: manager-role rules: - apiGroups: - - app.github.com + - batch resources: - - appdeployments - - caches - - operations - - requirements + - jobs verbs: - create - delete @@ -20,29 +17,26 @@ rules: - update - watch - apiGroups: - - app.github.com + - batch resources: - - appdeployments/finalizers - - caches/finalizers - - operations/finalizers - - requirements/finalizers + - jobs/finalizers verbs: - update - apiGroups: - - app.github.com + - batch resources: - - appdeployments/status - - caches/status - - operations/status - - requirements/status + - jobs/status verbs: - get - patch - update - apiGroups: - - batch + - controller.azure.github.com resources: - - jobs + - appdeployments + - caches + - operations + - requirements verbs: - create - delete @@ -52,15 +46,21 @@ rules: - update - watch - apiGroups: - - batch + - controller.azure.github.com resources: - - jobs/finalizers + - appdeployments/finalizers + - caches/finalizers + - operations/finalizers + - requirements/finalizers verbs: - update - apiGroups: - - batch + - controller.azure.github.com resources: - - jobs/status + - appdeployments/status + - caches/status + - operations/status + - requirements/status verbs: - get - patch diff --git a/config/samples/app_v1_appdeployment.yaml b/config/samples/app_v1alpha1_appdeployment.yaml similarity index 80% rename from config/samples/app_v1_appdeployment.yaml rename to config/samples/app_v1alpha1_appdeployment.yaml index e96cd9f..cfb286a 100644 --- a/config/samples/app_v1_appdeployment.yaml +++ b/config/samples/app_v1alpha1_appdeployment.yaml @@ -1,4 +1,4 @@ -apiVersion: app.github.com/v1 +apiVersion: controller.azure.github.com/v1alhpa1 kind: AppDeployment metadata: labels: diff --git a/config/samples/app_v1_cache.yaml b/config/samples/app_v1alpha1_cache.yaml similarity index 79% rename from config/samples/app_v1_cache.yaml rename to config/samples/app_v1alpha1_cache.yaml index cf78bd0..c7ec19c 100644 --- a/config/samples/app_v1_cache.yaml +++ b/config/samples/app_v1alpha1_cache.yaml @@ -1,4 +1,4 @@ -apiVersion: app.github.com/v1 +apiVersion: controller.azure.github.com/v1alpha1 kind: Cache metadata: labels: diff --git a/config/samples/app_v1_operation.yaml b/config/samples/app_v1alpha1_operation.yaml similarity index 80% rename from config/samples/app_v1_operation.yaml rename to config/samples/app_v1alpha1_operation.yaml index 786066f..4bbd909 100644 --- a/config/samples/app_v1_operation.yaml +++ b/config/samples/app_v1alpha1_operation.yaml @@ -1,4 +1,4 @@ -apiVersion: app.github.com/v1 +apiVersion: controller.azure.github.com/v1alpha1 kind: Operation metadata: labels: diff --git a/config/samples/app_v1_requirement.yaml b/config/samples/app_v1alpha1_requirement.yaml similarity index 80% rename from config/samples/app_v1_requirement.yaml rename to config/samples/app_v1alpha1_requirement.yaml index 48b908f..64da6db 100644 --- a/config/samples/app_v1_requirement.yaml +++ b/config/samples/app_v1alpha1_requirement.yaml @@ -1,4 +1,4 @@ -apiVersion: app.github.com/v1 +apiVersion: controller.azure.github.com/v1alpha1 kind: Requirement metadata: labels: diff --git a/internal/controller/appdeployment_adapter.go b/internal/controller/appdeployment_adapter.go index 74a615b..26df5c7 100644 --- a/internal/controller/appdeployment_adapter.go +++ b/internal/controller/appdeployment_adapter.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" apdutil "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) @@ -31,13 +31,13 @@ type AppDeploymentAdapterInterface interface { } type AppDeploymentAdapter struct { - appDeployment *appsv1.AppDeployment + appDeployment *v1alpha1.AppDeployment logger logr.Logger client client.Client recorder record.EventRecorder } -func NewAppDeploymentAdapter(ctx context.Context, appDeployment *appsv1.AppDeployment, logger logr.Logger, client client.Client, recorder record.EventRecorder) AppDeploymentAdapterInterface { +func NewAppDeploymentAdapter(ctx context.Context, appDeployment *v1alpha1.AppDeployment, logger logr.Logger, client client.Client, recorder record.EventRecorder) AppDeploymentAdapterInterface { if appdeploymentAdapter, ok := ctx.Value(appdeploymentAdapterContextKey{}).(AppDeploymentAdapterInterface); ok { return appdeploymentAdapter } @@ -108,7 +108,7 @@ func (a *AppDeploymentAdapter) EnsureDependenciesReady(ctx context.Context) (rec // list all dependencies and check if they are ready for _, dep := range a.appDeployment.Spec.Dependencies { // check if dependency is ready - appdeployment := &appsv1.AppDeployment{} + appdeployment := &v1alpha1.AppDeployment{} realAppName := apdutil.OperationScopedAppDeployment(dep, a.appDeployment.Spec.OpId) if err := a.client.Get(ctx, client.ObjectKey{Namespace: a.appDeployment.Namespace, Name: realAppName}, appdeployment); err != nil { a.logger.V(1).Error(err, "dependency not found", "dependency", realAppName) diff --git a/internal/controller/appdeployment_adapter_test.go b/internal/controller/appdeployment_adapter_test.go index deca909..21ec534 100644 --- a/internal/controller/appdeployment_adapter_test.go +++ b/internal/controller/appdeployment_adapter_test.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" apdutil "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" @@ -23,8 +23,8 @@ import ( const testOpId = "test-op-id" -var validAppDeployment = &appsv1.AppDeployment{ - Spec: appsv1.AppDeploymentSpec{ +var validAppDeployment = &v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: newTestJobSpec(), Teardown: newTestJobSpec(), OpId: testOpId, @@ -86,7 +86,7 @@ func TestAppDeploymentAdapter_EnsureApplicationValid(t *testing.T) { }) t.Run("Sad path: application return error", func(t *testing.T) { - appDeployment := &appsv1.AppDeployment{} + appDeployment := &v1alpha1.AppDeployment{} adapter := NewAppDeploymentAdapter(ctx, appDeployment, logger, mockClient, mockRecorder) assert.NotNil(t, adapter) res, err := adapter.EnsureApplicationValid(ctx) @@ -257,15 +257,15 @@ func TestAppDeploymentAdapter_EnsureDependenciesReady(t *testing.T) { } adapter := NewAppDeploymentAdapter(ctx, appDeployment, logger, mockClient, mockRecorder) - dependendApp := &appsv1.AppDeployment{ - Status: appsv1.AppDeploymentStatus{ + dependendApp := &v1alpha1.AppDeployment{ + Status: v1alpha1.AppDeploymentStatus{ Phase: apdutil.PhaseReady, }, } - mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&appsv1.AppDeployment{}), gomock.Any()).DoAndReturn( + mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.AppDeployment{}), gomock.Any()).DoAndReturn( func(ctx context.Context, key client.ObjectKey, obj runtime.Object, opts ...client.GetOption) error { - *obj.(*appsv1.AppDeployment) = *dependendApp + *obj.(*v1alpha1.AppDeployment) = *dependendApp assert.Equal(t, "test-op-id-test-app-1", key.Name) return nil }).Times(1) @@ -287,7 +287,7 @@ func TestAppDeploymentAdapter_EnsureDependenciesReady(t *testing.T) { } adapter := NewAppDeploymentAdapter(ctx, appDeployment, logger, mockClient, mockRecorder) - mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&appsv1.AppDeployment{}), gomock.Any()).Return(assert.AnError).Times(1) + mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.AppDeployment{}), gomock.Any()).Return(assert.AnError).Times(1) res, err := adapter.EnsureDependenciesReady(ctx) assert.ErrorContains(t, err, "dependency not found: test-op-id-test-app-1") @@ -305,15 +305,15 @@ func TestAppDeploymentAdapter_EnsureDependenciesReady(t *testing.T) { } adapter := NewAppDeploymentAdapter(ctx, appDeployment, logger, mockClient, mockRecorder) - dependendApp := &appsv1.AppDeployment{ - Status: appsv1.AppDeploymentStatus{ + dependendApp := &v1alpha1.AppDeployment{ + Status: v1alpha1.AppDeploymentStatus{ Phase: apdutil.PhasePending, }, } - mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&appsv1.AppDeployment{}), gomock.Any()).DoAndReturn( + mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.AppDeployment{}), gomock.Any()).DoAndReturn( func(ctx context.Context, key client.ObjectKey, obj runtime.Object, opts ...client.GetOption) error { - *obj.(*appsv1.AppDeployment) = *dependendApp + *obj.(*v1alpha1.AppDeployment) = *dependendApp assert.Equal(t, "test-op-id-test-app-1", key.Name) return nil }).Times(1) @@ -392,7 +392,7 @@ func TestAppDeploymentAdapter_EnsureDeployingFinished(t *testing.T) { mockStatusWriter := mockpkg.NewMockStatusWriter(mockStatusCtrl) mockClient.EXPECT().Status().Return(mockStatusWriter).AnyTimes() scheme := runtime.NewScheme() - _ = appsv1.AddToScheme(scheme) + _ = v1alpha1.AddToScheme(scheme) mockClient.EXPECT().Scheme().Return(scheme).AnyTimes() appDeployment := validAppDeployment.DeepCopy() @@ -434,7 +434,7 @@ func TestAppDeploymentAdapter_EnsureDeployingFinished(t *testing.T) { mockStatusWriter := mockpkg.NewMockStatusWriter(mockStatusCtrl) mockClient.EXPECT().Status().Return(mockStatusWriter).AnyTimes() scheme := runtime.NewScheme() - _ = appsv1.AddToScheme(scheme) + _ = v1alpha1.AddToScheme(scheme) mockClient.EXPECT().Scheme().Return(scheme).AnyTimes() appDeployment := validAppDeployment.DeepCopy() @@ -550,7 +550,7 @@ func TestAppDeploymentAdapter_EnsureTeardownFinished(t *testing.T) { mockStatusWriter := mockpkg.NewMockStatusWriter(mockStatusCtrl) mockClient.EXPECT().Status().Return(mockStatusWriter).AnyTimes() scheme := runtime.NewScheme() - _ = appsv1.AddToScheme(scheme) + _ = v1alpha1.AddToScheme(scheme) mockClient.EXPECT().Scheme().Return(scheme).AnyTimes() adapter := NewAppDeploymentAdapter(ctx, appDeployment, logger, mockClient, mockRecorder) @@ -579,7 +579,7 @@ func TestAppDeploymentAdapter_EnsureTeardownFinished(t *testing.T) { mockStatusWriter := mockpkg.NewMockStatusWriter(mockStatusCtrl) mockClient.EXPECT().Status().Return(mockStatusWriter).AnyTimes() scheme := runtime.NewScheme() - _ = appsv1.AddToScheme(scheme) + _ = v1alpha1.AddToScheme(scheme) mockClient.EXPECT().Scheme().Return(scheme).AnyTimes() adapter := NewAppDeploymentAdapter(ctx, appDeployment, logger, mockClient, mockRecorder) diff --git a/internal/controller/appdeployment_controller.go b/internal/controller/appdeployment_controller.go index 2e4aae3..f7a384d 100644 --- a/internal/controller/appdeployment_controller.go +++ b/internal/controller/appdeployment_controller.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" apdutil "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) @@ -40,9 +40,9 @@ type AppDeploymentReconciler struct { recorder record.EventRecorder } -// +kubebuilder:rbac:groups=app.github.com,resources=appdeployments,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=app.github.com,resources=appdeployments/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=app.github.com,resources=appdeployments/finalizers,verbs=update +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=appdeployments,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=appdeployments/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=appdeployments/finalizers,verbs=update // +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=batch,resources=jobs/status,verbs=get;update;patch // +kubebuilder:rbac:groups=batch,resources=jobs/finalizers,verbs=update @@ -58,7 +58,7 @@ type AppDeploymentReconciler struct { // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.4/pkg/reconcile func (r *AppDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.FromContext(ctx).WithValues(apdutil.LogKeyAppDeploymentName, req.NamespacedName) - appdeployment := &appsv1.AppDeployment{} + appdeployment := &v1alpha1.AppDeployment{} if err := r.Get(ctx, req.NamespacedName, appdeployment); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -99,7 +99,7 @@ func (r *AppDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error { if owner == nil { return nil } - if owner.APIVersion != appsv1.GroupVersion.String() || owner.Kind != "AppDeployment" { + if owner.APIVersion != v1alpha1.GroupVersion.String() || owner.Kind != "AppDeployment" { return nil } return []string{owner.Name} @@ -110,7 +110,7 @@ func (r *AppDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error { r.recorder = mgr.GetEventRecorderFor("AppDeployment") return ctrl.NewControllerManagedBy(mgr). - For(&appsv1.AppDeployment{}). + For(&v1alpha1.AppDeployment{}). Owns(&batchv1.Job{}). WithOptions(controller.Options{ MaxConcurrentReconciles: 100, diff --git a/internal/controller/appdeployment_controller_test.go b/internal/controller/appdeployment_controller_test.go index d23b162..6aa444d 100644 --- a/internal/controller/appdeployment_controller_test.go +++ b/internal/controller/appdeployment_controller_test.go @@ -32,7 +32,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ctrlmocks "github.com/Azure/operation-cache-controller/internal/controller/mocks" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" @@ -97,8 +97,8 @@ var _ = Describe("AppDeployment Controller", func() { Name: resourceName, Namespace: "default", // TODO(user):Modify as needed } - appdeployment := &appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + appdeployment := &v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test-op-id", Provision: newTestJobSpec(), Teardown: newTestJobSpec(), @@ -109,12 +109,12 @@ var _ = Describe("AppDeployment Controller", func() { By("creating the custom resource for the Kind AppDeployment") err := k8sClient.Get(ctx, typeNamespacedName, appdeployment) if err != nil && errors.IsNotFound(err) { - resource := &appv1.AppDeployment{ + resource := &v1alpha1.AppDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: resourceName, Namespace: "default", }, - Spec: appv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: newTestJobSpec(), Teardown: newTestJobSpec(), }} @@ -128,7 +128,7 @@ var _ = Describe("AppDeployment Controller", func() { AfterEach(func() { // TODO(user): Cleanup logic after each test, like removing the resource instance. - resource := &appv1.AppDeployment{} + resource := &v1alpha1.AppDeployment{} err := k8sClient.Get(ctx, typeNamespacedName, resource) Expect(err).NotTo(HaveOccurred()) diff --git a/internal/controller/cache_adapter.go b/internal/controller/cache_adapter.go index 867bf1a..ca8cfd9 100644 --- a/internal/controller/cache_adapter.go +++ b/internal/controller/cache_adapter.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ctrlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" @@ -30,7 +30,7 @@ type CacheAdapterInterface interface { } type CacheAdapter struct { - cache *appsv1.Cache + cache *v1alpha1.Cache logger logr.Logger client client.Client scheme *runtime.Scheme @@ -39,7 +39,7 @@ type CacheAdapter struct { } func NewCacheAdapter(ctx context.Context, - cache *appsv1.Cache, logger logr.Logger, client client.Client, scheme *runtime.Scheme, recorder record.EventRecorder, + cache *v1alpha1.Cache, logger logr.Logger, client client.Client, scheme *runtime.Scheme, recorder record.EventRecorder, fn func(owner, controlled metav1.Object, scheme *runtime.Scheme, opts ...controllerutil.OwnerReferenceOption) error) CacheAdapterInterface { return &CacheAdapter{ cache: cache, @@ -100,7 +100,7 @@ func (c *CacheAdapter) CalculateKeepAliveCount(ctx context.Context) (reconciler. return reconciler.RequeueOnErrorOrContinue(c.updateStatus(ctx)) } -func (c *CacheAdapter) createOperationsAsync(ctx context.Context, ops []*appsv1.Operation) error { +func (c *CacheAdapter) createOperationsAsync(ctx context.Context, ops []*v1alpha1.Operation) error { wg := sync.WaitGroup{} errChan := make(chan error, len(ops)) for _, op := range ops { @@ -119,7 +119,7 @@ func (c *CacheAdapter) createOperationsAsync(ctx context.Context, ops []*appsv1. return errs } -func (c *CacheAdapter) deleteOperationsAsync(ctx context.Context, ops []*appsv1.Operation) error { +func (c *CacheAdapter) deleteOperationsAsync(ctx context.Context, ops []*v1alpha1.Operation) error { wg := sync.WaitGroup{} errChan := make(chan error, len(ops)) for _, op := range ops { @@ -138,12 +138,12 @@ func (c *CacheAdapter) deleteOperationsAsync(ctx context.Context, ops []*appsv1. return errs } -func operationReady(op *appsv1.Operation) bool { +func operationReady(op *v1alpha1.Operation) bool { return op.Status.Phase == oputils.PhaseReconciled } -func (c *CacheAdapter) initOperationFromCache(operationName string) *appsv1.Operation { - op := &appsv1.Operation{} +func (c *CacheAdapter) initOperationFromCache(operationName string) *v1alpha1.Operation { + op := &v1alpha1.Operation{} annotations := op.GetAnnotations() if annotations == nil { @@ -171,7 +171,7 @@ func (c *CacheAdapter) initOperationFromCache(operationName string) *appsv1.Oper } func (c *CacheAdapter) AdjustCache(ctx context.Context) (reconciler.OperationResult, error) { - var ownedOps appsv1.OperationList + var ownedOps v1alpha1.OperationList if err := c.client.List(ctx, &ownedOps, client.InNamespace(c.cache.Namespace), client.MatchingFields{cacheOwnerKey: c.cache.Name}); err != nil { return reconciler.RequeueWithError(err) } @@ -191,7 +191,7 @@ func (c *CacheAdapter) AdjustCache(ctx context.Context) (reconciler.OperationRes case cacheBalance > 0: // remove all the not available operations and cut available operations down to keepAliveCount availableCacheNumToRemove := cacheBalance - opsToRemove := []*appsv1.Operation{} + opsToRemove := []*v1alpha1.Operation{} for _, op := range ownedOps.Items { if !operationReady(&op) { opsToRemove = append(opsToRemove, &op) @@ -209,7 +209,7 @@ func (c *CacheAdapter) AdjustCache(ctx context.Context) (reconciler.OperationRes case cacheBalance < 0: if len(ownedOps.Items) < keepAliveCount { // also count not available operations, create new operations to meet the keepAliveCount - opsToCreate := []*appsv1.Operation{} + opsToCreate := []*v1alpha1.Operation{} opsNumToCreate := keepAliveCount - len(ownedOps.Items) for range opsNumToCreate { opName := fmt.Sprintf("cached-operation-%s-%s", c.cache.Status.CacheKey[:8], strings.ToLower(ctrlutils.GenerateRandomString(5))) diff --git a/internal/controller/cache_adapter_test.go b/internal/controller/cache_adapter_test.go index 3f9e116..d24ae2c 100644 --- a/internal/controller/cache_adapter_test.go +++ b/internal/controller/cache_adapter_test.go @@ -16,7 +16,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" ctrlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" @@ -24,7 +24,7 @@ import ( func TestNewCacheAdapter(t *testing.T) { t.Run("NewCacheAdapter", func(t *testing.T) { - testCache := &appsv1.Cache{} + testCache := &v1alpha1.Cache{} testlogger := logr.Logger{} scheme := runtime.NewScheme() var ( @@ -40,8 +40,8 @@ func TestNewCacheAdapter(t *testing.T) { }) } -func getTestApps() []appsv1.ApplicationSpec { - return []appsv1.ApplicationSpec{ +func getTestApps() []v1alpha1.ApplicationSpec { + return []v1alpha1.ApplicationSpec{ { Name: "test-app-available", Provision: batchv1.JobSpec{ @@ -72,15 +72,15 @@ func TestCacheCheckCacheExpiry(t *testing.T) { t.Run("happy path", func(t *testing.T) { t.Run("cache not expired", func(t *testing.T) { - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ + Spec: v1alpha1.CacheSpec{ ExpireTime: time.Now().Add(1 * time.Hour).Format(time.RFC3339), }, - Status: appsv1.CacheStatus{}, + Status: v1alpha1.CacheStatus{}, } adapter := NewCacheAdapter(ctx, testCache, testlogger, mockClient, scheme, mockRecorder, ctrl.SetControllerReference) assert.NotNil(t, adapter) @@ -91,15 +91,15 @@ func TestCacheCheckCacheExpiry(t *testing.T) { assert.Equal(t, false, res.CancelRequest) }) t.Run("cache expired", func(t *testing.T) { - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ + Spec: v1alpha1.CacheSpec{ ExpireTime: time.Now().Add(-1 * time.Hour).Format(time.RFC3339), }, - Status: appsv1.CacheStatus{}, + Status: v1alpha1.CacheStatus{}, } adapter := NewCacheAdapter(ctx, testCache, testlogger, mockClient, scheme, mockRecorder, ctrl.SetControllerReference) assert.NotNil(t, adapter) @@ -111,13 +111,13 @@ func TestCacheCheckCacheExpiry(t *testing.T) { assert.Equal(t, true, res.CancelRequest) }) t.Run("cache expireTime not set", func(t *testing.T) { - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{}, - Status: appsv1.CacheStatus{}, + Spec: v1alpha1.CacheSpec{}, + Status: v1alpha1.CacheStatus{}, } adapter := NewCacheAdapter(ctx, testCache, testlogger, mockClient, scheme, mockRecorder, ctrl.SetControllerReference) assert.NotNil(t, adapter) @@ -131,15 +131,15 @@ func TestCacheCheckCacheExpiry(t *testing.T) { t.Run("negative cases", func(t *testing.T) { t.Run("invalid expire time", func(t *testing.T) { - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ + Spec: v1alpha1.CacheSpec{ ExpireTime: "invalid-time", }, - Status: appsv1.CacheStatus{}, + Status: v1alpha1.CacheStatus{}, } adapter := NewCacheAdapter(ctx, testCache, testlogger, mockClient, scheme, mockRecorder, ctrl.SetControllerReference) assert.NotNil(t, adapter) @@ -175,17 +175,17 @@ func TestCacheEnsureCacheInitialized(t *testing.T) { testCacheKey := ctrlutils.NewCacheKeyFromApplications(testApps) t.Run("happy path", func(t *testing.T) { - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ - OperationTemplate: appsv1.OperationSpec{ + Spec: v1alpha1.CacheSpec{ + OperationTemplate: v1alpha1.OperationSpec{ Applications: testApps, }, }, - Status: appsv1.CacheStatus{}, + Status: v1alpha1.CacheStatus{}, } adapter := NewCacheAdapter(ctx, testCache, testlogger, mockClient, scheme, mockRecorder, ctrl.SetControllerReference) assert.NotNil(t, adapter) @@ -220,17 +220,17 @@ func TestCacheCalculateKeepAliveCount(t *testing.T) { testApps := getTestApps() t.Run("happy path", func(t *testing.T) { - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ - OperationTemplate: appsv1.OperationSpec{ + Spec: v1alpha1.CacheSpec{ + OperationTemplate: v1alpha1.OperationSpec{ Applications: testApps, }, }, - Status: appsv1.CacheStatus{}, + Status: v1alpha1.CacheStatus{}, } adapter := NewCacheAdapter(ctx, testCache, testlogger, mockClient, scheme, mockRecorder, ctrl.SetControllerReference) assert.NotNil(t, adapter) @@ -266,8 +266,8 @@ func TestCacheAdjustCache(t *testing.T) { testApps := getTestApps() testCacheKey := ctrlutils.NewCacheKeyFromApplications(testApps) - newOperation := &appsv1.Operation{ - Spec: appsv1.OperationSpec{ + newOperation := &v1alpha1.Operation{ + Spec: v1alpha1.OperationSpec{ Applications: testApps, }, ObjectMeta: metav1.ObjectMeta{ @@ -275,13 +275,13 @@ func TestCacheAdjustCache(t *testing.T) { Namespace: "test-ns", Labels: map[string]string{ctrlutils.LabelNameCacheKey: testCacheKey}, }, - Status: appsv1.OperationStatus{ + Status: v1alpha1.OperationStatus{ Phase: oputils.PhaseEmpty, }, } - availableOperation := &appsv1.Operation{ - Spec: appsv1.OperationSpec{ + availableOperation := &v1alpha1.Operation{ + Spec: v1alpha1.OperationSpec{ Applications: testApps, }, ObjectMeta: metav1.ObjectMeta{ @@ -289,7 +289,7 @@ func TestCacheAdjustCache(t *testing.T) { Namespace: "test-ns", Labels: map[string]string{ctrlutils.LabelNameCacheKey: testCacheKey}, }, - Status: appsv1.OperationStatus{ + Status: v1alpha1.OperationStatus{ Phase: oputils.PhaseReconciled, }, } @@ -300,22 +300,22 @@ func TestCacheAdjustCache(t *testing.T) { t.Run("cache balance = 0", func(t *testing.T) { t.Run("happy path", func(t *testing.T) { - resOperations := appsv1.OperationList{Items: []appsv1.Operation{ + resOperations := v1alpha1.OperationList{Items: []v1alpha1.Operation{ *newOperation.DeepCopy(), *availableOperation.DeepCopy(), *availableOperation.DeepCopy(), }} - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ - OperationTemplate: appsv1.OperationSpec{ + Spec: v1alpha1.CacheSpec{ + OperationTemplate: v1alpha1.OperationSpec{ Applications: testApps, }, }, - Status: appsv1.CacheStatus{ + Status: v1alpha1.CacheStatus{ CacheKey: testCacheKey, KeepAliveCount: 2, }, @@ -335,25 +335,25 @@ func TestCacheAdjustCache(t *testing.T) { t.Run("cache balance > 0", func(t *testing.T) { t.Run("happy path", func(t *testing.T) { - resOperationItems := []appsv1.Operation{ + resOperationItems := []v1alpha1.Operation{ *newOperation.DeepCopy(), *availableOperation.DeepCopy(), *availableOperation.DeepCopy(), *availableOperation.DeepCopy(), *availableOperation.DeepCopy(), } - resOperations := appsv1.OperationList{Items: resOperationItems} - testCache := &appsv1.Cache{ + resOperations := v1alpha1.OperationList{Items: resOperationItems} + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ - OperationTemplate: appsv1.OperationSpec{ + Spec: v1alpha1.CacheSpec{ + OperationTemplate: v1alpha1.OperationSpec{ Applications: testApps, }, }, - Status: appsv1.CacheStatus{ + Status: v1alpha1.CacheStatus{ CacheKey: testCacheKey, KeepAliveCount: 2, }, @@ -374,21 +374,21 @@ func TestCacheAdjustCache(t *testing.T) { t.Run("cache balance < 0", func(t *testing.T) { t.Run("happy path", func(t *testing.T) { - resOperations := appsv1.OperationList{Items: []appsv1.Operation{ + resOperations := v1alpha1.OperationList{Items: []v1alpha1.Operation{ *newOperation.DeepCopy(), *availableOperation.DeepCopy(), }} - testCache := &appsv1.Cache{ + testCache := &v1alpha1.Cache{ ObjectMeta: metav1.ObjectMeta{ Name: "test-cache", Namespace: "test-ns", }, - Spec: appsv1.CacheSpec{ - OperationTemplate: appsv1.OperationSpec{ + Spec: v1alpha1.CacheSpec{ + OperationTemplate: v1alpha1.OperationSpec{ Applications: testApps, }, }, - Status: appsv1.CacheStatus{ + Status: v1alpha1.CacheStatus{ CacheKey: testCacheKey, KeepAliveCount: 3, }, diff --git a/internal/controller/cache_controller.go b/internal/controller/cache_controller.go index 1309186..21069d9 100644 --- a/internal/controller/cache_controller.go +++ b/internal/controller/cache_controller.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) @@ -43,11 +43,11 @@ type CacheReconciler struct { recorder record.EventRecorder } -// +kubebuilder:rbac:groups=app.github.com,resources=caches,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=app.github.com,resources=caches/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=app.github.com,resources=caches/finalizers,verbs=update -// +kubebuilder:rbac:groups=app.github.com,resources=operations,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=app.github.com,resources=operations/status,verbs=get +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=caches,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=caches/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=caches/finalizers,verbs=update +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=operations,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=operations/status,verbs=get // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. @@ -60,7 +60,7 @@ type CacheReconciler struct { // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.19.1/pkg/reconcile func (r *CacheReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.FromContext(ctx) - cache := &appsv1.Cache{} + cache := &v1alpha1.Cache{} if err := r.Get(ctx, req.NamespacedName, cache); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -98,13 +98,13 @@ var cacheOwnerKey = ".metadata.controller.cache" func cacheOperationIndexerFunc(obj client.Object) []string { // grab the operation object, extract the owner... - operation := obj.(*appsv1.Operation) + operation := obj.(*v1alpha1.Operation) owner := metav1.GetControllerOf(operation) if owner == nil { return nil } // ...make sure it's a Cache... - if owner.APIVersion != appsv1.GroupVersion.String() || owner.Kind != "Cache" { + if owner.APIVersion != v1alpha1.GroupVersion.String() || owner.Kind != "Cache" { return nil } // ...and if so, return it @@ -113,15 +113,15 @@ func cacheOperationIndexerFunc(obj client.Object) []string { // SetupWithManager sets up the controller with the Manager. func (r *CacheReconciler) SetupWithManager(mgr ctrl.Manager) error { // +gocover:ignore:block init controller - if err := mgr.GetFieldIndexer().IndexField(context.Background(), &appsv1.Operation{}, cacheOwnerKey, cacheOperationIndexerFunc); err != nil { // +gocover:ignore:block init controller + if err := mgr.GetFieldIndexer().IndexField(context.Background(), &v1alpha1.Operation{}, cacheOwnerKey, cacheOperationIndexerFunc); err != nil { // +gocover:ignore:block init controller return err } // +gocover:ignore:block init controller r.recorder = mgr.GetEventRecorderFor("Cache") return ctrl.NewControllerManagedBy(mgr). - For(&appsv1.Cache{}). - Owns(&appsv1.Operation{}). + For(&v1alpha1.Cache{}). + Owns(&v1alpha1.Operation{}). WithOptions(controller.Options{ MaxConcurrentReconciles: 50, }). diff --git a/internal/controller/cache_controller_test.go b/internal/controller/cache_controller_test.go index 539021d..9b81515 100644 --- a/internal/controller/cache_controller_test.go +++ b/internal/controller/cache_controller_test.go @@ -34,11 +34,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/controller/mocks" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - appsv1 "github.com/Azure/operation-cache-controller/api/v1" ) func TestReconcile(t *testing.T) { @@ -117,12 +116,12 @@ func TestReconcileHandler(t *testing.T) { func TestCacheOperationIndexerFunc(t *testing.T) { t.Run("with Cache owner", func(t *testing.T) { // Create an operation with a Cache owner - operation := &appsv1.Operation{ + operation := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: "test-operation", OwnerReferences: []metav1.OwnerReference{ { - APIVersion: appsv1.GroupVersion.String(), + APIVersion: v1alpha1.GroupVersion.String(), Kind: "Cache", Name: "test-cache", Controller: func() *bool { b := true; return &b }(), @@ -140,7 +139,7 @@ func TestCacheOperationIndexerFunc(t *testing.T) { t.Run("with no owner", func(t *testing.T) { // Create an operation with no owner - operation := &appsv1.Operation{ + operation := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: "test-operation", }, @@ -155,12 +154,12 @@ func TestCacheOperationIndexerFunc(t *testing.T) { t.Run("with non-Cache owner", func(t *testing.T) { // Create an operation with a non-Cache owner - operation := &appsv1.Operation{ + operation := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: "test-operation", OwnerReferences: []metav1.OwnerReference{ { - APIVersion: appsv1.GroupVersion.String(), + APIVersion: v1alpha1.GroupVersion.String(), Kind: "Requirement", Name: "test-requirement", Controller: func() *bool { b := true; return &b }(), @@ -178,12 +177,12 @@ func TestCacheOperationIndexerFunc(t *testing.T) { t.Run("with non-controller owner", func(t *testing.T) { // Create an operation with a non-controller owner reference - operation := &appsv1.Operation{ + operation := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: "test-operation", OwnerReferences: []metav1.OwnerReference{ { - APIVersion: appsv1.GroupVersion.String(), + APIVersion: v1alpha1.GroupVersion.String(), Kind: "Cache", Name: "test-cache", Controller: func() *bool { b := false; return &b }(), @@ -201,7 +200,7 @@ func TestCacheOperationIndexerFunc(t *testing.T) { t.Run("with different API version", func(t *testing.T) { // Create an operation with a different API version - operation := &appsv1.Operation{ + operation := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: "test-operation", OwnerReferences: []metav1.OwnerReference{ @@ -255,20 +254,20 @@ var _ = Describe("Cache Controller", func() { // Name: resourceName, // Namespace: "default", // TODO(user):Modify as needed // } - // cache := &appv1.Cache{} + // cache := &v1alpha1.Cache{} // BeforeEach(func() { // By("creating the custom resource for the Kind Cache") // err := k8sClient.Get(ctx, typeNamespacedName, cache) // if err != nil && errors.IsNotFound(err) { - // resource := &appv1.Cache{ + // resource := &v1alpha1.Cache{ // ObjectMeta: metav1.ObjectMeta{ // Name: resourceName, // Namespace: "default", // }, - // Spec: appv1.CacheSpec{ - // OperationTemplate: appv1.OperationSpec{ - // Applications: []appv1.ApplicationSpec{ + // Spec: v1alpha1.CacheSpec{ + // OperationTemplate: v1alpha1.OperationSpec{ + // Applications: []v1alpha1.ApplicationSpec{ // { // Name: "app1", // Provision: newTestJobSpec(), @@ -286,7 +285,7 @@ var _ = Describe("Cache Controller", func() { // AfterEach(func() { // // TODO(user): Cleanup logic after each test, like removing the resource instance. - // resource := &appv1.Cache{} + // resource := &v1alpha1.Cache{} // err := k8sClient.Get(ctx, typeNamespacedName, resource) // Expect(err).NotTo(HaveOccurred()) diff --git a/internal/controller/operation_adapter.go b/internal/controller/operation_adapter.go index bca8c89..4e49132 100644 --- a/internal/controller/operation_adapter.go +++ b/internal/controller/operation_adapter.go @@ -14,7 +14,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ctlrutils "github.com/Azure/operation-cache-controller/internal/utils/controller" apdutils "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" @@ -32,13 +32,13 @@ type OperationAdapterInterface interface { } type OperationAdapter struct { - operation *appsv1.Operation + operation *v1alpha1.Operation logger logr.Logger client client.Client recorder record.EventRecorder } -func NewOperationAdapter(ctx context.Context, operation *appsv1.Operation, logger logr.Logger, client client.Client, recorder record.EventRecorder) OperationAdapterInterface { +func NewOperationAdapter(ctx context.Context, operation *v1alpha1.Operation, logger logr.Logger, client client.Client, recorder record.EventRecorder) OperationAdapterInterface { if operationAdapter, ok := ctx.Value(operationAdapterContextKey{}).(OperationAdapterInterface); ok { return operationAdapter } @@ -199,7 +199,7 @@ func (o *OperationAdapter) reconcilingApplications(ctx context.Context) error { // check if all expected app deployments are ready for _, app := range expectedAppDeployments { - appdeployment := &appsv1.AppDeployment{} + appdeployment := &v1alpha1.AppDeployment{} if err := o.client.Get(ctx, client.ObjectKey{Namespace: app.Namespace, Name: app.Name}, appdeployment); err != nil { return fmt.Errorf("failed to get app deployment: %w", err) } @@ -212,14 +212,14 @@ func (o *OperationAdapter) reconcilingApplications(ctx context.Context) error { return nil } -func (o *OperationAdapter) expectedAppDeployments() []appsv1.AppDeployment { - return lo.Map(o.operation.Spec.Applications, func(app appsv1.ApplicationSpec, index int) appsv1.AppDeployment { - return appsv1.AppDeployment{ +func (o *OperationAdapter) expectedAppDeployments() []v1alpha1.AppDeployment { + return lo.Map(o.operation.Spec.Applications, func(app v1alpha1.ApplicationSpec, index int) v1alpha1.AppDeployment { + return v1alpha1.AppDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: apdutils.OperationScopedAppDeployment(app.Name, o.operation.Status.OperationID), Namespace: o.operation.Namespace, }, - Spec: appsv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: o.operation.Status.OperationID, Provision: app.Provision, Teardown: app.Teardown, @@ -229,13 +229,13 @@ func (o *OperationAdapter) expectedAppDeployments() []appsv1.AppDeployment { }) } -func (o *OperationAdapter) listCurrentAppDeployments(ctx context.Context) ([]appsv1.AppDeployment, error) { - appDeploymentList := &appsv1.AppDeploymentList{} +func (o *OperationAdapter) listCurrentAppDeployments(ctx context.Context) ([]v1alpha1.AppDeployment, error) { + appDeploymentList := &v1alpha1.AppDeploymentList{} if err := o.client.List(ctx, appDeploymentList, client.MatchingFields{operationOwnerKey: o.operation.Name}); err != nil { return nil, fmt.Errorf("failed to list appDeployments: %w", err) } - return lo.Map(appDeploymentList.Items, func(app appsv1.AppDeployment, index int) appsv1.AppDeployment { - return appsv1.AppDeployment{ + return lo.Map(appDeploymentList.Items, func(app v1alpha1.AppDeployment, index int) v1alpha1.AppDeployment { + return v1alpha1.AppDeployment{ ObjectMeta: app.ObjectMeta, Spec: app.Spec, } diff --git a/internal/controller/operation_adapter_test.go b/internal/controller/operation_adapter_test.go index b40f21a..7a93571 100644 --- a/internal/controller/operation_adapter_test.go +++ b/internal/controller/operation_adapter_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" adputils "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" @@ -22,14 +22,14 @@ import ( ) var ( - emptyOperation = &appsv1.Operation{} - validOperation = &appsv1.Operation{ + emptyOperation = &v1alpha1.Operation{} + validOperation = &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: "test-operation", Namespace: "default", }, - Spec: appsv1.OperationSpec{ - Applications: []appsv1.ApplicationSpec{ + Spec: v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{ { Name: "test-app1", Provision: newTestJobSpec(), @@ -45,22 +45,22 @@ var ( }, }, } - emptyAppDeploymentList = &appsv1.AppDeploymentList{} + emptyAppDeploymentList = &v1alpha1.AppDeploymentList{} - validAppDeploymentList = &appsv1.AppDeploymentList{ - Items: []appsv1.AppDeployment{ + validAppDeploymentList = &v1alpha1.AppDeploymentList{ + Items: []v1alpha1.AppDeployment{ { ObjectMeta: metav1.ObjectMeta{ Name: "test-app1", Namespace: "default", }, - Spec: appsv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test-operation", Provision: newTestJobSpec(), Teardown: newTestJobSpec(), Dependencies: []string{"test-app2"}, }, - Status: appsv1.AppDeploymentStatus{ + Status: v1alpha1.AppDeploymentStatus{ Phase: adputils.PhaseReady, }, }, @@ -69,26 +69,26 @@ var ( Name: "test-app2", Namespace: "default", }, - Spec: appsv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test-operation", Provision: newTestJobSpec(), Teardown: newTestJobSpec(), }, - Status: appsv1.AppDeploymentStatus{ + Status: v1alpha1.AppDeploymentStatus{ Phase: adputils.PhaseReady, }, }, }, } - changedValidAppDeploymentList = &appsv1.AppDeploymentList{ - Items: []appsv1.AppDeployment{ + changedValidAppDeploymentList = &v1alpha1.AppDeploymentList{ + Items: []v1alpha1.AppDeployment{ { ObjectMeta: metav1.ObjectMeta{ Name: "test-app2", Namespace: "default", }, - Spec: appsv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test-operation", Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ @@ -111,7 +111,7 @@ var ( }, Teardown: newTestJobSpec(), }, - Status: appsv1.AppDeploymentStatus{ + Status: v1alpha1.AppDeploymentStatus{ Phase: adputils.PhaseReady, }, }, @@ -120,12 +120,12 @@ var ( Name: "test-app3", Namespace: "default", }, - Spec: appsv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test-operation", Provision: newTestJobSpec(), Teardown: newTestJobSpec(), }, - Status: appsv1.AppDeploymentStatus{ + Status: v1alpha1.AppDeploymentStatus{ Phase: adputils.PhaseReady, }, }, @@ -279,15 +279,15 @@ func TestOperationAdapter_EnsureAllAppsAreReady(t *testing.T) { operation.Status.Phase = oputils.PhaseReconciling appList := emptyAppDeploymentList.DeepCopy() - mockClient.EXPECT().List(ctx, appList, gomock.Any()).DoAndReturn(func(ctx context.Context, list *appsv1.AppDeploymentList, opts ...interface{}) error { + mockClient.EXPECT().List(ctx, appList, gomock.Any()).DoAndReturn(func(ctx context.Context, list *v1alpha1.AppDeploymentList, opts ...interface{}) error { *list = *changedValidAppDeploymentList return nil }) scheme := runtime.NewScheme() - utilruntime.Must(appsv1.AddToScheme(scheme)) + utilruntime.Must(v1alpha1.AddToScheme(scheme)) mockClient.EXPECT().Scheme().Return(scheme).AnyTimes() mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj runtime.Object, opt ...interface{}) error { - *obj.(*appsv1.AppDeployment) = appsv1.AppDeployment{} + *obj.(*v1alpha1.AppDeployment) = v1alpha1.AppDeployment{} return nil }).AnyTimes() mockClient.EXPECT().Create(ctx, gomock.Any()).Return(nil) @@ -317,16 +317,16 @@ func TestOperationAdapter_EnsureAllAppsAreReady(t *testing.T) { operation.Status.Phase = oputils.PhaseReconciling appList := emptyAppDeploymentList.DeepCopy() - mockClient.EXPECT().List(ctx, appList, gomock.Any()).DoAndReturn(func(ctx context.Context, list *appsv1.AppDeploymentList, opts ...interface{}) error { + mockClient.EXPECT().List(ctx, appList, gomock.Any()).DoAndReturn(func(ctx context.Context, list *v1alpha1.AppDeploymentList, opts ...interface{}) error { *list = *validAppDeploymentList return nil }) scheme := runtime.NewScheme() mockClient.EXPECT().Scheme().Return(scheme).AnyTimes() - readyAppDeployment := &appsv1.AppDeployment{} + readyAppDeployment := &v1alpha1.AppDeployment{} readyAppDeployment.Status.Phase = adputils.PhaseReady mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj runtime.Object, opt ...interface{}) error { - *obj.(*appsv1.AppDeployment) = *readyAppDeployment + *obj.(*v1alpha1.AppDeployment) = *readyAppDeployment return nil }).AnyTimes() mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) diff --git a/internal/controller/operation_controller.go b/internal/controller/operation_controller.go index 3e8bda6..1c16f4a 100644 --- a/internal/controller/operation_controller.go +++ b/internal/controller/operation_controller.go @@ -27,7 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) @@ -38,9 +38,9 @@ type OperationReconciler struct { recorder record.EventRecorder } -// +kubebuilder:rbac:groups=app.github.com,resources=operations,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=app.github.com,resources=operations/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=app.github.com,resources=operations/finalizers,verbs=update +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=operations,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=operations/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=operations/finalizers,verbs=update // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. @@ -54,7 +54,7 @@ type OperationReconciler struct { func (r *OperationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.FromContext(ctx) - operation := &appsv1.Operation{} + operation := &v1alpha1.Operation{} if err := r.Get(ctx, req.NamespacedName, operation); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -89,16 +89,16 @@ var operationOwnerKey = ".operation.metadata.controller" // SetupWithManager sets up the controller with the Manager. func (r *OperationReconciler) SetupWithManager(mgr ctrl.Manager) error { - if err := mgr.GetFieldIndexer().IndexField(context.Background(), &appsv1.AppDeployment{}, operationOwnerKey, + if err := mgr.GetFieldIndexer().IndexField(context.Background(), &v1alpha1.AppDeployment{}, operationOwnerKey, func(rawObj client.Object) []string { // grab the AppDeployment object, extract the owner - adp := rawObj.(*appsv1.AppDeployment) + adp := rawObj.(*v1alpha1.AppDeployment) owner := metav1.GetControllerOf(adp) if owner == nil { return nil } // Make sure the owner is a Operation object - if owner.APIVersion != appsv1.GroupVersion.String() || owner.Kind != "Operation" { + if owner.APIVersion != v1alpha1.GroupVersion.String() || owner.Kind != "Operation" { return nil } return []string{owner.Name} @@ -109,8 +109,8 @@ func (r *OperationReconciler) SetupWithManager(mgr ctrl.Manager) error { r.recorder = mgr.GetEventRecorderFor("Operation") return ctrl.NewControllerManagedBy(mgr). - For(&appsv1.Operation{}). - Owns(&appsv1.AppDeployment{}). + For(&v1alpha1.Operation{}). + Owns(&v1alpha1.AppDeployment{}). WithOptions(controller.Options{ MaxConcurrentReconciles: 100, }). diff --git a/internal/controller/operation_controller_test.go b/internal/controller/operation_controller_test.go index 9b6f89e..783889a 100644 --- a/internal/controller/operation_controller_test.go +++ b/internal/controller/operation_controller_test.go @@ -25,14 +25,13 @@ import ( . "github.com/onsi/gomega" "go.uber.org/mock/gomock" "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/reconcile" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - appv1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/controller/mocks" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) @@ -69,13 +68,13 @@ var _ = Describe("Operation Controller", func() { Name: "test-operation", Namespace: "default", } - operation := &appv1.Operation{ + operation := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: key.Name, Namespace: key.Namespace, }, - Spec: appv1.OperationSpec{ - Applications: []appv1.ApplicationSpec{ + Spec: v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{ { Name: "test-app1", Provision: newTestJobSpec(), @@ -93,7 +92,7 @@ var _ = Describe("Operation Controller", func() { Expect(k8sClient.Create(context.Background(), operation)).To(Succeed()) - feched := &appv1.Operation{} + feched := &v1alpha1.Operation{} Eventually(func() bool { err := k8sClient.Get(context.Background(), key, feched) return err == nil @@ -186,19 +185,19 @@ var _ = Describe("Operation Controller", func() { Name: resourceName, Namespace: "default", // TODO(user):Modify as needed } - operation := &appv1.Operation{} + operation := &v1alpha1.Operation{} BeforeEach(func() { By("creating the custom resource for the Kind Operation") err := k8sClient.Get(ctx, typeNamespacedName, operation) if err != nil && errors.IsNotFound(err) { - resource := &appv1.Operation{ + resource := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: resourceName, Namespace: "default", }, - Spec: appv1.OperationSpec{ - Applications: []appv1.ApplicationSpec{ + Spec: v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{ { Name: "test-app1", Provision: newTestJobSpec(), @@ -219,7 +218,7 @@ var _ = Describe("Operation Controller", func() { AfterEach(func() { // TODO(user): Cleanup logic after each test, like removing the resource instance. - resource := &appv1.Operation{} + resource := &v1alpha1.Operation{} err := k8sClient.Get(ctx, typeNamespacedName, resource) Expect(err).NotTo(HaveOccurred()) diff --git a/internal/controller/requirement_adapter.go b/internal/controller/requirement_adapter.go index 9eb2d27..97ab214 100644 --- a/internal/controller/requirement_adapter.go +++ b/internal/controller/requirement_adapter.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ctlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" cacheutils "github.com/Azure/operation-cache-controller/internal/utils/controller/cache" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" @@ -34,13 +34,13 @@ type RequirementAdapterInterface interface { } type RequirementAdapter struct { - requirement *appsv1.Requirement + requirement *v1alpha1.Requirement logger logr.Logger client client.Client recorder record.EventRecorder } -func NewRequirementAdapter(ctx context.Context, requirement *appsv1.Requirement, logger logr.Logger, client client.Client, recorder record.EventRecorder) RequirementAdapterInterface { +func NewRequirementAdapter(ctx context.Context, requirement *v1alpha1.Requirement, logger logr.Logger, client client.Client, recorder record.EventRecorder) RequirementAdapterInterface { if requirementAdapter, ok := ctx.Value(requirementAdapterContextKey{}).(RequirementAdapterInterface); ok { return requirementAdapter } @@ -149,7 +149,7 @@ func (r *RequirementAdapter) EnsureCacheExisted(ctx context.Context) (reconciler r.logger.Error(fmt.Errorf("empty cache key"), "Cache key is empty, cannot proceed with cache creation") return reconciler.RequeueWithError(fmt.Errorf("empty cache key")) } - cache := &appsv1.Cache{} + cache := &v1alpha1.Cache{} // Try to get the Cache CR if err := r.client.Get(ctx, types.NamespacedName{Name: r.defaultCacheName(), Namespace: r.requirement.Namespace}, cache); err != nil { if client.IgnoreNotFound(err) != nil { @@ -159,7 +159,7 @@ func (r *RequirementAdapter) EnsureCacheExisted(ctx context.Context) (reconciler // cache cr not found, create it cache.Name = r.defaultCacheName() cache.Namespace = r.requirement.Namespace - cache.Spec = appsv1.CacheSpec{ + cache.Spec = v1alpha1.CacheSpec{ OperationTemplate: r.requirement.Spec.Template, ExpireTime: cacheutils.DefaultCacheExpireTime(), } @@ -187,7 +187,7 @@ func (r *RequirementAdapter) EnsureCachedOperationAcquired(ctx context.Context) r.setCacheMissStatus() return reconciler.RequeueOnErrorOrContinue(r.client.Status().Update(ctx, r.requirement)) } - operation := &appsv1.Operation{} + operation := &v1alpha1.Operation{} if err := r.client.Get(ctx, types.NamespacedName{Name: r.requirement.Status.OperationName, Namespace: r.requirement.Namespace}, operation); err != nil { r.setCacheMissStatus() return reconciler.RequeueOnErrorOrContinue(fmt.Errorf("failed to get operation %s: %w", r.requirement.Status.OperationName, err)) @@ -218,19 +218,19 @@ func (r *RequirementAdapter) EnsureCachedOperationAcquired(ctx context.Context) return reconciler.RequeueOnErrorOrContinue(r.client.Status().Update(ctx, r.requirement)) } -func (r *RequirementAdapter) acquireCachedOperation(ctx context.Context, operation *appsv1.Operation) error { +func (r *RequirementAdapter) acquireCachedOperation(ctx context.Context, operation *v1alpha1.Operation) error { operation.Annotations[oputils.AcquiredAnnotationKey] = time.Now().Format(time.RFC3339) operation.OwnerReferences = []metav1.OwnerReference{r.ownerReference()} return r.client.Update(ctx, operation) } -func (r *RequirementAdapter) getOperation() (*appsv1.Operation, error) { +func (r *RequirementAdapter) getOperation() (*v1alpha1.Operation, error) { namespacedName := types.NamespacedName{ Name: r.requirement.Status.OperationName, Namespace: r.requirement.Namespace, } - operation := &appsv1.Operation{} + operation := &v1alpha1.Operation{} if err := r.client.Get(context.Background(), namespacedName, operation); err != nil { return nil, fmt.Errorf("failed to get operation %s: %w", r.requirement.Status.OperationName, err) } @@ -247,7 +247,7 @@ func (r *RequirementAdapter) updateOperation() error { } func (r *RequirementAdapter) createOperation() error { - operation := &appsv1.Operation{ + operation := &v1alpha1.Operation{ ObjectMeta: metav1.ObjectMeta{ Name: r.requirement.Status.OperationName, Namespace: r.requirement.Namespace, diff --git a/internal/controller/requirement_adapter_test.go b/internal/controller/requirement_adapter_test.go index 753ea8e..89cffdf 100644 --- a/internal/controller/requirement_adapter_test.go +++ b/internal/controller/requirement_adapter_test.go @@ -16,7 +16,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" ctlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" @@ -26,12 +26,12 @@ import ( var ( testOperationName = "test-operation" - emptyRequirement = &appsv1.Requirement{} - validRequirement = &appsv1.Requirement{ - Spec: appsv1.RequirementSpec{ + emptyRequirement = &v1alpha1.Requirement{} + validRequirement = &v1alpha1.Requirement{ + Spec: v1alpha1.RequirementSpec{ ExpireAt: time.Now().Add(time.Hour).Format(time.RFC3339), - Template: appsv1.OperationSpec{ - Applications: []appsv1.ApplicationSpec{ + Template: v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{ { Name: "test-app1", Provision: newTestJobSpec(), @@ -48,8 +48,8 @@ var ( }, }, } - validCache = &appsv1.Cache{ - Status: appsv1.CacheStatus{ + validCache = &v1alpha1.Cache{ + Status: v1alpha1.CacheStatus{ AvailableCaches: []string{"test-cache1", "test-cache2"}, }, } @@ -220,11 +220,11 @@ func TestRequirementAdapter_EnsureCacheExisted(t *testing.T) { cache := validCache.DeepCopy() mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(cache), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Cache) = *cache + *obj.(*v1alpha1.Cache) = *cache return nil }) - mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&appsv1.Cache{})).Return(nil) + mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&v1alpha1.Cache{})).Return(nil) mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) res, err := adapter.EnsureCacheExisted(ctx) assert.NoError(t, err) @@ -283,10 +283,10 @@ func TestRequirementAdapter_EnsureCacheExisted(t *testing.T) { cache.Status.AvailableCaches = nil mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(cache), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Cache) = *cache + *obj.(*v1alpha1.Cache) = *cache return nil }) - mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&appsv1.Cache{})).Return(nil) + mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&v1alpha1.Cache{})).Return(nil) mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) res, err := adapter.EnsureCacheExisted(ctx) assert.NoError(t, err) @@ -348,8 +348,8 @@ func TestRequirementAdapter_EnsureCachedOperationAcquired(t *testing.T) { }, } - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Operation) = *operation + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { + *obj.(*v1alpha1.Operation) = *operation return nil }) mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) @@ -380,8 +380,8 @@ func TestRequirementAdapter_EnsureCachedOperationAcquired(t *testing.T) { }, } - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Operation) = *operation + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { + *obj.(*v1alpha1.Operation) = *operation return nil }) mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) @@ -403,11 +403,11 @@ func TestRequirementAdapter_EnsureCachedOperationAcquired(t *testing.T) { operation := validOperation.DeepCopy() operation.Annotations = map[string]string{} - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Operation) = *operation + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { + *obj.(*v1alpha1.Operation) = *operation return nil }) - mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&appsv1.Operation{})).Return(nil) + mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&v1alpha1.Operation{})).Return(nil) mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) res, err := adapter.EnsureCachedOperationAcquired(ctx) @@ -424,7 +424,7 @@ func TestRequirementAdapter_EnsureCachedOperationAcquired(t *testing.T) { requirement.Status.Phase = rqutils.PhaseCacheChecking adapter := NewRequirementAdapter(ctx, requirement, logger, mockClient, mockRecorder) - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).Return(assert.AnError) + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).Return(assert.AnError) res, err := adapter.EnsureCachedOperationAcquired(ctx) assert.ErrorIs(t, err, assert.AnError) @@ -441,11 +441,11 @@ func TestRequirementAdapter_EnsureCachedOperationAcquired(t *testing.T) { operation := validOperation.DeepCopy() operation.Annotations = map[string]string{} - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Operation) = *operation + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { + *obj.(*v1alpha1.Operation) = *operation return nil }) - mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&appsv1.Operation{})).Return(assert.AnError) + mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&v1alpha1.Operation{})).Return(assert.AnError) res, err := adapter.EnsureCachedOperationAcquired(ctx) assert.Error(t, err) @@ -495,11 +495,11 @@ func TestRequirementAdapter_EnsureOperationReady(t *testing.T) { requirement.Status.CacheKey = "test-cache-key" operaition := validOperation.DeepCopy() - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Operation) = *operaition + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { + *obj.(*v1alpha1.Operation) = *operaition return nil }) - mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&appsv1.Operation{})).Return(nil) + mockClient.EXPECT().Update(ctx, gomock.AssignableToTypeOf(&v1alpha1.Operation{})).Return(nil) mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) adapter := NewRequirementAdapter(ctx, requirement, logger, mockClient, mockRecorder) @@ -514,7 +514,7 @@ func TestRequirementAdapter_EnsureOperationReady(t *testing.T) { requirement.Status.Phase = rqutils.PhaseReady adapter := NewRequirementAdapter(ctx, requirement, logger, mockClient, mockRecorder) - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).Return(assert.AnError) + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).Return(assert.AnError) res, err := adapter.EnsureOperationReady(ctx) assert.ErrorIs(t, err, assert.AnError) @@ -530,8 +530,8 @@ func TestRequirementAdapter_EnsureOperationReady(t *testing.T) { operation := validOperation.DeepCopy() operation.Status.Phase = oputils.PhaseReconciling - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Operation) = *operation + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { + *obj.(*v1alpha1.Operation) = *operation return nil }) @@ -550,8 +550,8 @@ func TestRequirementAdapter_EnsureOperationReady(t *testing.T) { operation := validOperation.DeepCopy() operation.Status.Phase = oputils.PhaseReconciled - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - *obj.(*appsv1.Operation) = *operation + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { + *obj.(*v1alpha1.Operation) = *operation return nil }) mockStatusWriter.EXPECT().Update(gomock.Any(), gomock.Any()).Return(nil) @@ -569,10 +569,10 @@ func TestRequirementAdapter_EnsureOperationReady(t *testing.T) { requirement.Status.OperationName = testOperationName requirement.Status.Phase = rqutils.PhaseOperating scheme := runtime.NewScheme() - _ = appsv1.AddToScheme(scheme) + _ = v1alpha1.AddToScheme(scheme) adapter := NewRequirementAdapter(ctx, requirement, logger, mockClient, mockRecorder) - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).Return(apierrors.NewNotFound(schema.GroupResource{Group: "appsv1", Resource: "Operation"}, "operation not found")) + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).Return(apierrors.NewNotFound(schema.GroupResource{Group: "appsv1", Resource: "Operation"}, "operation not found")) mockClient.EXPECT().Scheme().Return(scheme) mockClient.EXPECT().Create(ctx, gomock.Any()).Return(nil) @@ -588,8 +588,8 @@ func TestRequirementAdapter_EnsureOperationReady(t *testing.T) { requirement.Status.Phase = rqutils.PhaseOperating adapter := NewRequirementAdapter(ctx, requirement, logger, mockClient, mockRecorder) schema := runtime.NewScheme() - _ = appsv1.AddToScheme(schema) - mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Operation{}), gomock.Any()).Return(assert.AnError) + _ = v1alpha1.AddToScheme(schema) + mockClient.EXPECT().Get(ctx, gomock.Any(), gomock.AssignableToTypeOf(&v1alpha1.Operation{}), gomock.Any()).Return(assert.AnError) mockClient.EXPECT().Scheme().Return(schema) mockClient.EXPECT().Create(ctx, gomock.Any()).Return(assert.AnError) diff --git a/internal/controller/requirement_controller.go b/internal/controller/requirement_controller.go index c33e436..456aff7 100644 --- a/internal/controller/requirement_controller.go +++ b/internal/controller/requirement_controller.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) @@ -41,9 +41,9 @@ type RequirementReconciler struct { recorder record.EventRecorder } -// +kubebuilder:rbac:groups=app.github.com,resources=requirements,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=app.github.com,resources=requirements/status,verbs=get;update;patch -// +kubebuilder:rbac:groups=app.github.com,resources=requirements/finalizers,verbs=update +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=requirements,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=requirements/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=controller.azure.github.com,resources=requirements/finalizers,verbs=update // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. @@ -57,7 +57,7 @@ type RequirementReconciler struct { func (r *RequirementReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { logger := log.FromContext(ctx).WithValues("requirement", req.NamespacedName) - requirement := &appsv1.Requirement{} + requirement := &v1alpha1.Requirement{} if err := r.Get(ctx, req.NamespacedName, requirement); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -94,16 +94,16 @@ var requirementOwnerKey = ".requirement.metadata.controller" // SetupWithManager sets up the controller with the Manager. func (r *RequirementReconciler) SetupWithManager(mgr ctrl.Manager) error { - if err := mgr.GetFieldIndexer().IndexField(context.Background(), &appsv1.Operation{}, requirementOwnerKey, + if err := mgr.GetFieldIndexer().IndexField(context.Background(), &v1alpha1.Operation{}, requirementOwnerKey, func(rawObj client.Object) []string { // grab the Operation object, extract the owner - op := rawObj.(*appsv1.Operation) + op := rawObj.(*v1alpha1.Operation) owner := metav1.GetControllerOf(op) if owner == nil { return nil } // Make sure the owner is a Requirement object - if owner.APIVersion != appsv1.GroupVersion.String() || owner.Kind != "Requirement" { + if owner.APIVersion != v1alpha1.GroupVersion.String() || owner.Kind != "Requirement" { return nil } return []string{owner.Name} @@ -114,8 +114,8 @@ func (r *RequirementReconciler) SetupWithManager(mgr ctrl.Manager) error { r.recorder = mgr.GetEventRecorderFor("Requirement") return ctrl.NewControllerManagedBy(mgr). - For(&appsv1.Requirement{}). - Owns(&appsv1.Operation{}). + For(&v1alpha1.Requirement{}). + Owns(&v1alpha1.Operation{}). WithOptions(controller.Options{ MaxConcurrentReconciles: 100, }). diff --git a/internal/controller/requirement_controller_test.go b/internal/controller/requirement_controller_test.go index a1ebc84..ac7424a 100644 --- a/internal/controller/requirement_controller_test.go +++ b/internal/controller/requirement_controller_test.go @@ -34,7 +34,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/controller/mocks" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) @@ -71,14 +71,14 @@ var _ = Describe("Requirement Controller", func() { Name: "test-requirement", Namespace: "default", } - requirement := &appsv1.Requirement{ + requirement := &v1alpha1.Requirement{ ObjectMeta: metav1.ObjectMeta{ Name: key.Name, Namespace: key.Namespace, }, - Spec: appsv1.RequirementSpec{ - Template: appsv1.OperationSpec{ - Applications: []appsv1.ApplicationSpec{ + Spec: v1alpha1.RequirementSpec{ + Template: v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{ { Name: "test-app", Provision: batchv1.JobSpec{ @@ -110,7 +110,7 @@ var _ = Describe("Requirement Controller", func() { } Expect(k8sClient.Create(context.Background(), requirement)).Should(Succeed()) - fetchedRequirement := &appsv1.Requirement{} + fetchedRequirement := &v1alpha1.Requirement{} Eventually(func() bool { err := k8sClient.Get(context.Background(), key, fetchedRequirement) return err == nil @@ -200,20 +200,20 @@ var _ = Describe("Requirement Controller", func() { Name: resourceName, Namespace: "default", } - requirement := &appsv1.Requirement{} + requirement := &v1alpha1.Requirement{} BeforeEach(func() { By("Creating a new Requirement resource") err := k8sClient.Get(ctx, typeNamespacedName, requirement) if err != nil && errors.IsNotFound(err) { - resource := &appsv1.Requirement{ + resource := &v1alpha1.Requirement{ ObjectMeta: metav1.ObjectMeta{ Name: typeNamespacedName.Name, Namespace: typeNamespacedName.Namespace, }, - Spec: appsv1.RequirementSpec{ - Template: appsv1.OperationSpec{ - Applications: []appsv1.ApplicationSpec{ + Spec: v1alpha1.RequirementSpec{ + Template: v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{ { Name: "test-app", Provision: batchv1.JobSpec{ @@ -249,7 +249,7 @@ var _ = Describe("Requirement Controller", func() { AfterEach(func() { // TODO(user): Cleanup logic after each test, like removing the resource instance. - resource := &appsv1.Requirement{} + resource := &v1alpha1.Requirement{} err := k8sClient.Get(ctx, typeNamespacedName, resource) Expect(err).NotTo(HaveOccurred()) diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index a616515..47477bb 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -32,7 +32,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" // +kubebuilder:scaffold:imports ) @@ -59,7 +59,7 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) var err error - err = appv1.AddToScheme(scheme.Scheme) + err = v1alpha1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) // +kubebuilder:scaffold:scheme diff --git a/internal/utils/controller/appdeployment/conditions.go b/internal/utils/controller/appdeployment/conditions.go index c026aea..f2cfc77 100644 --- a/internal/utils/controller/appdeployment/conditions.go +++ b/internal/utils/controller/appdeployment/conditions.go @@ -5,7 +5,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + appv1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func ClearConditions(ctx context.Context, appdeployment *appv1.AppDeployment) { diff --git a/internal/utils/controller/appdeployment/conditions_test.go b/internal/utils/controller/appdeployment/conditions_test.go index c732452..014763f 100644 --- a/internal/utils/controller/appdeployment/conditions_test.go +++ b/internal/utils/controller/appdeployment/conditions_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + appv1 "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" ) diff --git a/internal/utils/controller/appdeployment/job.go b/internal/utils/controller/appdeployment/job.go index 8feb7cc..4c83082 100644 --- a/internal/utils/controller/appdeployment/job.go +++ b/internal/utils/controller/appdeployment/job.go @@ -7,7 +7,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) const ( @@ -35,23 +35,23 @@ func validJName(appName, operationId, jobType string) string { return originName } -func ProvisionJobFromAppDeploymentSpec(appDeployment *appv1.AppDeployment) *batchv1.Job { +func ProvisionJobFromAppDeploymentSpec(appDeployment *v1alpha1.AppDeployment) *batchv1.Job { return jobFromAppDeploymentSpec(appDeployment, JobTypeProvision) } -func TeardownJobFromAppDeploymentSpec(appDeployment *appv1.AppDeployment) *batchv1.Job { +func TeardownJobFromAppDeploymentSpec(appDeployment *v1alpha1.AppDeployment) *batchv1.Job { return jobFromAppDeploymentSpec(appDeployment, JobTypeTeardown) } -func GetProvisionJobName(appDeployment *appv1.AppDeployment) string { +func GetProvisionJobName(appDeployment *v1alpha1.AppDeployment) string { return validJName(appDeployment.Name, appDeployment.Spec.OpId, JobTypeProvision) } -func GetTeardownJobName(appDeployment *appv1.AppDeployment) string { +func GetTeardownJobName(appDeployment *v1alpha1.AppDeployment) string { return validJName(appDeployment.Name, appDeployment.Spec.OpId, JobTypeTeardown) } -func jobFromAppDeploymentSpec(appDeployment *appv1.AppDeployment, suffix string) *batchv1.Job { +func jobFromAppDeploymentSpec(appDeployment *v1alpha1.AppDeployment, suffix string) *batchv1.Job { ops := jobOptions{ name: validJName(appDeployment.Name, appDeployment.Spec.OpId, suffix), namespace: appDeployment.Namespace, diff --git a/internal/utils/controller/appdeployment/job_test.go b/internal/utils/controller/appdeployment/job_test.go index 34727f4..96bdadf 100644 --- a/internal/utils/controller/appdeployment/job_test.go +++ b/internal/utils/controller/appdeployment/job_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + appv1 "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/stretchr/testify/assert" batchv1 "k8s.io/api/batch/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/utils/controller/appdeployment/validate.go b/internal/utils/controller/appdeployment/validate.go index 3d3170b..262225d 100644 --- a/internal/utils/controller/appdeployment/validate.go +++ b/internal/utils/controller/appdeployment/validate.go @@ -8,12 +8,12 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) -type Validater func(*appv1.AppDeployment) error +type Validater func(*v1alpha1.AppDeployment) error -func Validate(ap *appv1.AppDeployment) error { +func Validate(ap *v1alpha1.AppDeployment) error { var errs error validaters := []Validater{ validateJobSpec, @@ -27,8 +27,8 @@ func Validate(ap *appv1.AppDeployment) error { // validateJobSpec validates the container count in the AppDeployment Spec // * container count in AppDeployment Spec should be 1 // * initCountainer is not allowed -func validateJobSpec(ap *appv1.AppDeployment) error { - if equality.Semantic.DeepEqual(ap.Spec, appv1.AppDeploymentSpec{}) { +func validateJobSpec(ap *v1alpha1.AppDeployment) error { + if equality.Semantic.DeepEqual(ap.Spec, v1alpha1.AppDeploymentSpec{}) { return errors.New("spec of appdeployment is nil") } // provision job must be present diff --git a/internal/utils/controller/appdeployment/validate_test.go b/internal/utils/controller/appdeployment/validate_test.go index 48268c0..eed38be 100644 --- a/internal/utils/controller/appdeployment/validate_test.go +++ b/internal/utils/controller/appdeployment/validate_test.go @@ -8,20 +8,20 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appv1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/ptr" ) func TestValidate(t *testing.T) { tests := []struct { name string - app appv1.AppDeployment + app v1alpha1.AppDeployment wantErr bool }{ { name: "Valid AppDeployment", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -41,13 +41,13 @@ func TestValidate(t *testing.T) { }, { name: "Empty Spec", - app: appv1.AppDeployment{}, + app: v1alpha1.AppDeployment{}, wantErr: true, }, { name: "Invalid Provision Job", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test", Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ @@ -77,8 +77,8 @@ func TestValidate(t *testing.T) { }, { name: "Invalid TearDown Job", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test", Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ @@ -113,8 +113,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint activeDeadlineSeconds", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ ActiveDeadlineSeconds: ptr.Of(int64(1)), }, @@ -124,8 +124,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint backoffLimit", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ BackoffLimit: ptr.Of(int32(1)), }, @@ -135,8 +135,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint backoffLimitPerIndex", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ BackoffLimitPerIndex: ptr.Of(int32(1)), }, @@ -146,8 +146,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint completions", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Completions: ptr.Of(int32(1)), }, @@ -157,8 +157,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint completionMode", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ CompletionMode: ptr.Of(batchv1.NonIndexedCompletion), }, @@ -168,8 +168,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint managedBy", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ ManagedBy: ptr.Of("test"), }, @@ -179,8 +179,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint manualSelector", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ ManualSelector: ptr.Of(true), }, @@ -190,8 +190,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint maxFailedIndexes", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ MaxFailedIndexes: ptr.Of(int32(1)), }, @@ -201,8 +201,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint parallelism", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Parallelism: ptr.Of(int32(1)), }, @@ -212,8 +212,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint podFailurePolicy", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ PodFailurePolicy: ptr.Of(batchv1.PodFailurePolicy{ Rules: []batchv1.PodFailurePolicyRule{ @@ -229,8 +229,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint podReplacementPolicy", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ PodReplacementPolicy: ptr.Of(batchv1.Failed), }, @@ -240,8 +240,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint Selectors", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ @@ -255,8 +255,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint TTLSecondsAfterFinished", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ TTLSecondsAfterFinished: ptr.Of(int32(1)), }, @@ -266,8 +266,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint SuccessPolicy", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ CompletionMode: new(batchv1.CompletionMode), }, @@ -277,8 +277,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint Suspend", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Suspend: ptr.Of(true), }, @@ -288,8 +288,8 @@ func TestValidate(t *testing.T) { }, { name: "jobConstraint PodTemplate", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: "test", Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{}, @@ -300,8 +300,8 @@ func TestValidate(t *testing.T) { }, { name: "podConstraint name", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -325,8 +325,8 @@ func TestValidate(t *testing.T) { }, { name: "podConstraint namespace", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -350,8 +350,8 @@ func TestValidate(t *testing.T) { }, { name: "podConstraint volumes", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -377,8 +377,8 @@ func TestValidate(t *testing.T) { }, { name: "podConstraint initContainers", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -407,8 +407,8 @@ func TestValidate(t *testing.T) { }, { name: "podConstraint container count should be 1", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -435,8 +435,8 @@ func TestValidate(t *testing.T) { }, { name: "containerConstraint image is empty", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -456,8 +456,8 @@ func TestValidate(t *testing.T) { }, { name: "containerConstraint volumeMounts are not allowed", - app: appv1.AppDeployment{ - Spec: appv1.AppDeploymentSpec{ + app: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ diff --git a/internal/utils/controller/cache/cache.go b/internal/utils/controller/cache/cache.go index c40964e..0d3f973 100644 --- a/internal/utils/controller/cache/cache.go +++ b/internal/utils/controller/cache/cache.go @@ -4,10 +4,10 @@ import ( "math/rand" "time" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) -func RandomSelectCachedOperation(cache *appsv1.Cache) string { +func RandomSelectCachedOperation(cache *v1alpha1.Cache) string { if len(cache.Status.AvailableCaches) == 0 { return "" } diff --git a/internal/utils/controller/cache/cache_test.go b/internal/utils/controller/cache/cache_test.go index 8273c5c..ba57d46 100644 --- a/internal/utils/controller/cache/cache_test.go +++ b/internal/utils/controller/cache/cache_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestRandomSelectCachedOperation(t *testing.T) { @@ -21,8 +21,8 @@ func TestRandomSelectCachedOperation(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // ...existing setup code if any... - cacheInstance := &appsv1.Cache{ - Status: appsv1.CacheStatus{ + cacheInstance := &v1alpha1.Cache{ + Status: v1alpha1.CacheStatus{ AvailableCaches: tt.caches, }, } diff --git a/internal/utils/controller/cachekey.go b/internal/utils/controller/cachekey.go index 3303714..e1c2a76 100644 --- a/internal/utils/controller/cachekey.go +++ b/internal/utils/controller/cachekey.go @@ -9,7 +9,7 @@ import ( "github.com/samber/lo" corev1 "k8s.io/api/core/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) type AppCacheField struct { @@ -47,13 +47,13 @@ func (c *AppCacheField) NewCacheKey() string { return hex.EncodeToString(hasher.Sum(nil)) } -func NewCacheKeyFromApplications(apps []appsv1.ApplicationSpec) string { +func NewCacheKeyFromApplications(apps []v1alpha1.ApplicationSpec) string { // sort the apps by name to ensure consistent hashing sort.Slice(apps, func(i, j int) bool { return apps[i].Name < apps[j].Name }) - srcCacheKeys := lo.Reduce(apps, func(acc []string, app appsv1.ApplicationSpec, index int) []string { + srcCacheKeys := lo.Reduce(apps, func(acc []string, app v1alpha1.ApplicationSpec, index int) []string { return append(acc, AppCacheFieldFromApplicationProvision(app).NewCacheKey()) }, []string{}) @@ -65,7 +65,7 @@ func NewCacheKeyFromApplications(apps []appsv1.ApplicationSpec) string { return hex.EncodeToString(hasher.Sum(nil)) } -func AppCacheFieldFromApplicationProvision(app appsv1.ApplicationSpec) *AppCacheField { +func AppCacheFieldFromApplicationProvision(app v1alpha1.ApplicationSpec) *AppCacheField { return &AppCacheField{ Name: app.Name, Image: app.Provision.Template.Spec.Containers[0].Image, @@ -77,7 +77,7 @@ func AppCacheFieldFromApplicationProvision(app appsv1.ApplicationSpec) *AppCache } } -func AppCacheFieldFromApplicationTeardown(app appsv1.ApplicationSpec) *AppCacheField { +func AppCacheFieldFromApplicationTeardown(app v1alpha1.ApplicationSpec) *AppCacheField { return &AppCacheField{ Name: app.Name, Image: app.Teardown.Template.Spec.Containers[0].Image, diff --git a/internal/utils/controller/cachekey_test.go b/internal/utils/controller/cachekey_test.go index 23166d3..4d59560 100644 --- a/internal/utils/controller/cachekey_test.go +++ b/internal/utils/controller/cachekey_test.go @@ -7,7 +7,7 @@ import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestNewCacheKey(t *testing.T) { @@ -92,12 +92,12 @@ func TestNewCacheKey(t *testing.T) { func TestNewCacheKeyFromApplications(t *testing.T) { tests := []struct { name string - source []appsv1.ApplicationSpec + source []v1alpha1.ApplicationSpec expected string }{ { name: "basic", - source: []appsv1.ApplicationSpec{ + source: []v1alpha1.ApplicationSpec{ { Name: "test-app-1", Provision: batchv1.JobSpec{ @@ -118,7 +118,7 @@ func TestNewCacheKeyFromApplications(t *testing.T) { }, { name: "basic with dependencies", - source: []appsv1.ApplicationSpec{ + source: []v1alpha1.ApplicationSpec{ { Name: "test-app-1", Provision: batchv1.JobSpec{ @@ -156,7 +156,7 @@ func TestNewCacheKeyFromApplications(t *testing.T) { { name: "basic with multiple dependencies", - source: []appsv1.ApplicationSpec{ + source: []v1alpha1.ApplicationSpec{ { Name: "test-app-1", Provision: batchv1.JobSpec{ @@ -209,7 +209,7 @@ func TestNewCacheKeyFromApplications(t *testing.T) { }, { name: "basic with multiple dependencies and different order", - source: []appsv1.ApplicationSpec{ + source: []v1alpha1.ApplicationSpec{ { Name: "test-app-1", Provision: batchv1.JobSpec{ diff --git a/internal/utils/controller/operation/operation.go b/internal/utils/controller/operation/operation.go index 164a11c..de90fba 100644 --- a/internal/utils/controller/operation/operation.go +++ b/internal/utils/controller/operation/operation.go @@ -8,7 +8,7 @@ import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) // NewOperationId generates a new operation id which is an UUID. @@ -17,8 +17,8 @@ func NewOperationId() string { } // DiffAppDeployments returns the difference between two slices of AppDeployment. -func DiffAppDeployments(expected, actual []appsv1.AppDeployment, - equals func(a, b appsv1.AppDeployment) bool) (added, removed, updated []appsv1.AppDeployment) { +func DiffAppDeployments(expected, actual []v1alpha1.AppDeployment, + equals func(a, b v1alpha1.AppDeployment) bool) (added, removed, updated []v1alpha1.AppDeployment) { // Find added and updated AppDeployments. for _, e := range expected { found := false @@ -112,7 +112,7 @@ func isStringSliceIdentical(a, b []string) bool { return true } -func CompareProvisionJobs(a, b appsv1.AppDeployment) bool { +func CompareProvisionJobs(a, b v1alpha1.AppDeployment) bool { if sameProvisionJob := isJobResultIdentical(a.Spec.Provision, b.Spec.Provision); !sameProvisionJob { return false } @@ -128,7 +128,7 @@ func CompareProvisionJobs(a, b appsv1.AppDeployment) bool { return true } -func CompareTeardownJobs(a, b appsv1.AppDeployment) bool { +func CompareTeardownJobs(a, b v1alpha1.AppDeployment) bool { if sameTeardownJob := isJobResultIdentical(a.Spec.Teardown, b.Spec.Teardown); !sameTeardownJob { return false } diff --git a/internal/utils/controller/operation/operation_test.go b/internal/utils/controller/operation/operation_test.go index bb2569a..6cf1ec3 100644 --- a/internal/utils/controller/operation/operation_test.go +++ b/internal/utils/controller/operation/operation_test.go @@ -9,7 +9,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestNewOperationId(t *testing.T) { @@ -29,18 +29,18 @@ func TestNewOperationId(t *testing.T) { func TestDiffAppDeployments(t *testing.T) { tests := []struct { name string - expected []appsv1.AppDeployment - actual []appsv1.AppDeployment - equals func(a, b appsv1.AppDeployment) bool + expected []v1alpha1.AppDeployment + actual []v1alpha1.AppDeployment + equals func(a, b v1alpha1.AppDeployment) bool wantAdded int wantRemoved int wantUpdated int }{ { name: "basic example", - expected: []appsv1.AppDeployment{{ObjectMeta: metav1.ObjectMeta{Name: "app1"}}, {ObjectMeta: metav1.ObjectMeta{Name: "app2"}}}, - actual: []appsv1.AppDeployment{{ObjectMeta: metav1.ObjectMeta{Name: "app2"}}, {ObjectMeta: metav1.ObjectMeta{Name: "app3"}}}, - equals: func(a, b appsv1.AppDeployment) bool { return a.Name == b.Name }, + expected: []v1alpha1.AppDeployment{{ObjectMeta: metav1.ObjectMeta{Name: "app1"}}, {ObjectMeta: metav1.ObjectMeta{Name: "app2"}}}, + actual: []v1alpha1.AppDeployment{{ObjectMeta: metav1.ObjectMeta{Name: "app2"}}, {ObjectMeta: metav1.ObjectMeta{Name: "app3"}}}, + equals: func(a, b v1alpha1.AppDeployment) bool { return a.Name == b.Name }, wantAdded: 1, wantRemoved: 1, wantUpdated: 0, }, } @@ -57,14 +57,14 @@ func TestDiffAppDeployments(t *testing.T) { func TestCompareProvisionJobs(t *testing.T) { tests := []struct { name string - a appsv1.AppDeployment - b appsv1.AppDeployment + a v1alpha1.AppDeployment + b v1alpha1.AppDeployment want bool }{ { name: "different images", - a: appsv1.AppDeployment{ - Spec: appsv1.AppDeploymentSpec{ + a: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -75,8 +75,8 @@ func TestCompareProvisionJobs(t *testing.T) { Dependencies: []string{"dep1", "dep2"}, }, }, - b: appsv1.AppDeployment{ - Spec: appsv1.AppDeploymentSpec{ + b: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Provision: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -101,14 +101,14 @@ func TestCompareProvisionJobs(t *testing.T) { func TestCompareTeardownJobs(t *testing.T) { tests := []struct { name string - a appsv1.AppDeployment - b appsv1.AppDeployment + a v1alpha1.AppDeployment + b v1alpha1.AppDeployment want bool }{ { name: "different teardown images", - a: appsv1.AppDeployment{ - Spec: appsv1.AppDeploymentSpec{ + a: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Teardown: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -118,8 +118,8 @@ func TestCompareTeardownJobs(t *testing.T) { }, }, }, - b: appsv1.AppDeployment{ - Spec: appsv1.AppDeploymentSpec{ + b: v1alpha1.AppDeployment{ + Spec: v1alpha1.AppDeploymentSpec{ Teardown: batchv1.JobSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ diff --git a/internal/utils/controller/operation/status.go b/internal/utils/controller/operation/status.go index 703b886..69868be 100644 --- a/internal/utils/controller/operation/status.go +++ b/internal/utils/controller/operation/status.go @@ -3,9 +3,9 @@ package operation import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) -func ClearConditions(operation *appsv1.Operation) { +func ClearConditions(operation *v1alpha1.Operation) { operation.Status.Conditions = []metav1.Condition{} } diff --git a/internal/utils/controller/operation/status_test.go b/internal/utils/controller/operation/status_test.go index 72bff9d..f486914 100644 --- a/internal/utils/controller/operation/status_test.go +++ b/internal/utils/controller/operation/status_test.go @@ -6,11 +6,11 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestConditions(t *testing.T) { - operation := &appsv1.Operation{} + operation := &v1alpha1.Operation{} operation.Status.Conditions = []metav1.Condition{ { Type: "test", diff --git a/internal/utils/controller/requirement/status.go b/internal/utils/controller/requirement/status.go index 9cac96e..eaa5aef 100644 --- a/internal/utils/controller/requirement/status.go +++ b/internal/utils/controller/requirement/status.go @@ -3,16 +3,16 @@ package requirement import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) -func ClearConditions(r *appsv1.Requirement) { +func ClearConditions(r *v1alpha1.Requirement) { if r.Status.Conditions == nil { r.Status.Conditions = []metav1.Condition{} } } -func getCondition(r *appsv1.Requirement, conditionType string) (int, *metav1.Condition) { +func getCondition(r *v1alpha1.Requirement, conditionType string) (int, *metav1.Condition) { for i, condition := range r.Status.Conditions { if condition.Type == conditionType { return i, &condition @@ -21,12 +21,12 @@ func getCondition(r *appsv1.Requirement, conditionType string) (int, *metav1.Con return -1, nil } -func IsCacheMissed(r *appsv1.Requirement) bool { +func IsCacheMissed(r *v1alpha1.Requirement) bool { _, condition := getCondition(r, ConditionCachedOperationAcquired) return condition == nil || condition.Status == metav1.ConditionFalse } -func UpdateCondition(r *appsv1.Requirement, conditionType string, conditionStatus metav1.ConditionStatus, reason, message string) bool { +func UpdateCondition(r *v1alpha1.Requirement, conditionType string, conditionStatus metav1.ConditionStatus, reason, message string) bool { condition := &metav1.Condition{ Type: conditionType, Status: conditionStatus, diff --git a/internal/utils/controller/requirement/status_test.go b/internal/utils/controller/requirement/status_test.go index 76bf583..dadb2d3 100644 --- a/internal/utils/controller/requirement/status_test.go +++ b/internal/utils/controller/requirement/status_test.go @@ -7,14 +7,14 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appsv1 "github.com/Azure/operation-cache-controller/api/v1" + v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" ) // --- Test ClearConditions --- func TestClearConditions(t *testing.T) { // Requirement with nil Conditions. - req := &appsv1.Requirement{ - Status: appsv1.RequirementStatus{ + req := &v1alpha1.Requirement{ + Status: v1alpha1.RequirementStatus{ // Conditions nil for test. }, } @@ -58,8 +58,8 @@ func TestIsCacheMissed(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - req := &appsv1.Requirement{ - Status: appsv1.RequirementStatus{ + req := &v1alpha1.Requirement{ + Status: v1alpha1.RequirementStatus{ Conditions: tt.conditions, }, } @@ -72,9 +72,9 @@ func TestIsCacheMissed(t *testing.T) { // --- Test UpdateCondition --- func TestUpdateCondition(t *testing.T) { // Helper to create a Requirement with given conditions. - newReq := func(conds []metav1.Condition) *appsv1.Requirement { - return &appsv1.Requirement{ - Status: appsv1.RequirementStatus{ + newReq := func(conds []metav1.Condition) *v1alpha1.Requirement { + return &v1alpha1.Requirement{ + Status: v1alpha1.RequirementStatus{ Conditions: conds, }, } diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index 2cdbac7..bb15cc1 100644 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - v1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" rqutils "github.com/Azure/operation-cache-controller/internal/utils/controller/requirement" "github.com/Azure/operation-cache-controller/test/utils" ) @@ -36,13 +36,13 @@ var SimpleRequirementFeature = features.New("Simple Requirements"). return ctx }). Assess("requirement created successfully", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var requirement v1.Requirement + var requirement v1alpha1.Requirement if err := cfg.Client().Resources().Get(ctx, testRequirementName, utils.TestNamespace, &requirement); err != nil { t.Fatal(err) } assert.Equal(t, testRequirementName, requirement.Name) if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { - requirement := &v1.Requirement{} + requirement := &v1alpha1.Requirement{} if err := cfg.Client().Resources().Get(ctx, testRequirementName, utils.TestNamespace, requirement); err != nil { return false, err } @@ -56,14 +56,14 @@ var SimpleRequirementFeature = features.New("Simple Requirements"). return context.WithValue(ctx, requirementKey{}, &requirement) }). Teardown(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - requirement := ctx.Value(requirementKey{}).(*v1.Requirement) + requirement := ctx.Value(requirementKey{}).(*v1alpha1.Requirement) if err := cfg.Client().Resources().Delete(ctx, requirement); err != nil { t.Fatal(err) } return ctx }).Feature() -func newRequirementWithCache(name string) *v1.Requirement { +func newRequirementWithCache(name string) *v1alpha1.Requirement { requirement := utils.NewRequirement(name, utils.TestNamespace) requirement.Spec.EnableCache = true return requirement @@ -79,7 +79,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). return ctx }). Assess("cache requirement created and synced", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - var requirement v1.Requirement + var requirement v1alpha1.Requirement if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespace, &requirement); err != nil { t.Fatal(err) } @@ -87,7 +87,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). // Wait for requirement to be ready if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { - requirement := &v1.Requirement{} + requirement := &v1alpha1.Requirement{} if err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespace, requirement); err != nil { return false, err } @@ -100,7 +100,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). } cacheKey := requirement.Status.CacheKey // Get the associated Cache resource - cache := &v1.Cache{} + cache := &v1alpha1.Cache{} cacheName := "cache-" + cacheKey if err := cfg.Client().Resources().Get(ctx, cacheName, utils.TestNamespace, cache); err != nil { t.Fatal(err, "cache not found") @@ -109,25 +109,25 @@ var CachedRequirementFeature = features.New("Cached Requirements"). assert.Equal(t, cacheKey, cache.Status.CacheKey) // Get all Operations - var operations v1.OperationList + var operations v1alpha1.OperationList if err := cfg.Client().Resources().List(ctx, &operations); err != nil { t.Fatal(err, "failed to list operations") } // Verify one operation is owned by our requirement by checking owner references var ( - ownedByRequirement []v1.Operation - ownedByCache []v1.Operation + ownedByRequirement []v1alpha1.Operation + ownedByCache []v1alpha1.Operation ) for _, op := range operations.Items { for _, ownerRef := range op.OwnerReferences { - if ownerRef.APIVersion == v1.GroupVersion.String() && + if ownerRef.APIVersion == v1alpha1.GroupVersion.String() && ownerRef.Kind == "Requirement" && ownerRef.Name == requirement.Name && ownerRef.UID == requirement.UID { ownedByRequirement = append(ownedByRequirement, op) } - if ownerRef.APIVersion == v1.GroupVersion.String() && + if ownerRef.APIVersion == v1alpha1.GroupVersion.String() && ownerRef.Kind == "Cache" && ownerRef.Name == cache.Name && ownerRef.UID == cache.UID { @@ -146,7 +146,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). } // wait for the requirement to be deleted if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { - requirement := &v1.Requirement{} + requirement := &v1alpha1.Requirement{} err := cfg.Client().Resources().Get(ctx, cachedRequirementName, utils.TestNamespace, requirement) // err is not found, so requirement is deleted if err != nil { @@ -166,7 +166,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). t.Fatal(err) } - newRequirement := &v1.Requirement{} + newRequirement := &v1alpha1.Requirement{} // wait for the new requirement to be ready if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 60*time.Second, true, func(ctx context.Context) (bool, error) { if err := cfg.Client().Resources().Get(ctx, newCachedRequirementName, utils.TestNamespace, newRequirement); err != nil { @@ -191,24 +191,24 @@ var CachedRequirementFeature = features.New("Cached Requirements"). assert.True(t, cacheHit, "expected cache hit condition") // list operations and verify the new requirement has operation with the same name from original cache - var newOperations v1.OperationList + var newOperations v1alpha1.OperationList if err := cfg.Client().Resources().List(ctx, &newOperations); err != nil { t.Fatal(err, "failed to list operations") } var ( - ownedByNewRequirement []v1.Operation - ownedByCurrentCache []v1.Operation + ownedByNewRequirement []v1alpha1.Operation + ownedByCurrentCache []v1alpha1.Operation ) for _, op := range newOperations.Items { for _, ownerRef := range op.OwnerReferences { - if ownerRef.APIVersion == v1.GroupVersion.String() && + if ownerRef.APIVersion == v1alpha1.GroupVersion.String() && ownerRef.Kind == "Requirement" && ownerRef.Name == newCachedRequirementName && ownerRef.UID == newRequirement.UID { ownedByNewRequirement = append(ownedByNewRequirement, op) } - if ownerRef.APIVersion == v1.GroupVersion.String() && + if ownerRef.APIVersion == v1alpha1.GroupVersion.String() && ownerRef.Kind == "Cache" && ownerRef.Name == cacheName && ownerRef.UID == cache.UID { @@ -238,7 +238,7 @@ var CachedRequirementFeature = features.New("Cached Requirements"). return context.WithValue(ctx, requirementKey{}, newRequirement) }). Teardown(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - requirement := ctx.Value(requirementKey{}).(*v1.Requirement) + requirement := ctx.Value(requirementKey{}).(*v1alpha1.Requirement) if err := cfg.Client().Resources().Delete(ctx, requirement); err != nil { t.Fatal(err) } diff --git a/test/integration/main_test.go b/test/integration/main_test.go index ca20f70..ae9ea34 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -16,7 +16,7 @@ import ( "sigs.k8s.io/e2e-framework/pkg/envfuncs" "sigs.k8s.io/e2e-framework/support/kind" - v1 "github.com/Azure/operation-cache-controller/api/v1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/test/utils" ) @@ -29,7 +29,7 @@ var kindClusterName = "integration-test-cluster" func init() { log.SetLogger(zap.New(zap.WriteTo(os.Stdout), zap.UseDevMode(true))) - utilruntime.Must(v1.AddToScheme(scheme.Scheme)) + utilruntime.Must(v1alpha1.AddToScheme(scheme.Scheme)) } func TestMain(m *testing.M) { diff --git a/test/utils/resources.go b/test/utils/resources.go index 82217c8..9e619ca 100644 --- a/test/utils/resources.go +++ b/test/utils/resources.go @@ -1,10 +1,11 @@ package utils import ( - appsv1 "github.com/Azure/operation-cache-controller/api/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) const ( @@ -28,29 +29,29 @@ func NewTestJobSpec(name string) batchv1.JobSpec { } } -func NewTestApplicationSpec(name string) appsv1.ApplicationSpec { - return appsv1.ApplicationSpec{ +func NewTestApplicationSpec(name string) v1alpha1.ApplicationSpec { + return v1alpha1.ApplicationSpec{ Name: name, Provision: NewTestJobSpec("provision"), Teardown: NewTestJobSpec("teardown"), } } -func NewSimpleOperationSpec(name string) *appsv1.OperationSpec { - return &appsv1.OperationSpec{ - Applications: []appsv1.ApplicationSpec{NewTestApplicationSpec("app1")}, +func NewSimpleOperationSpec(name string) *v1alpha1.OperationSpec { + return &v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{NewTestApplicationSpec("app1")}, } } -func NewRequirement(name, namespace string) *appsv1.Requirement { - return &appsv1.Requirement{ +func NewRequirement(name, namespace string) *v1alpha1.Requirement { + return &v1alpha1.Requirement{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, }, - Spec: appsv1.RequirementSpec{ - Template: appsv1.OperationSpec{ - Applications: []appsv1.ApplicationSpec{NewTestApplicationSpec("app1")}, + Spec: v1alpha1.RequirementSpec{ + Template: v1alpha1.OperationSpec{ + Applications: []v1alpha1.ApplicationSpec{NewTestApplicationSpec("app1")}, }, }, } From 4c95e0e173f49c456e2a62463417f7c2c6d5c44e Mon Sep 17 00:00:00 2001 From: DQ Date: Thu, 17 Apr 2025 13:29:51 +1000 Subject: [PATCH 5/6] fix: correct typo in apiVersion of AppDeployment sample --- config/samples/app_v1alpha1_appdeployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/samples/app_v1alpha1_appdeployment.yaml b/config/samples/app_v1alpha1_appdeployment.yaml index cfb286a..967b5bb 100644 --- a/config/samples/app_v1alpha1_appdeployment.yaml +++ b/config/samples/app_v1alpha1_appdeployment.yaml @@ -1,4 +1,4 @@ -apiVersion: controller.azure.github.com/v1alhpa1 +apiVersion: controller.azure.github.com/v1alpha1 kind: AppDeployment metadata: labels: From 58565b03121f3f933dc56ce9f9bee1f9985983e6 Mon Sep 17 00:00:00 2001 From: DQ Date: Thu, 17 Apr 2025 13:54:18 +1000 Subject: [PATCH 6/6] fix: update import paths for v1alpha1 across multiple files --- internal/controller/appdeployment_adapter.go | 2 +- internal/controller/appdeployment_adapter_test.go | 2 +- internal/controller/appdeployment_controller.go | 2 +- internal/controller/cache_adapter.go | 2 +- internal/controller/cache_adapter_test.go | 2 +- internal/controller/cache_controller.go | 2 +- internal/controller/cache_controller_test.go | 9 ++------- internal/controller/operation_adapter.go | 2 +- internal/controller/operation_adapter_test.go | 2 +- internal/controller/operation_controller.go | 2 +- internal/controller/requirement_adapter.go | 2 +- internal/controller/requirement_adapter_test.go | 2 +- internal/controller/requirement_controller.go | 2 +- internal/controller/requirement_controller_test.go | 2 +- internal/utils/controller/appdeployment/conditions.go | 4 ++-- .../utils/controller/appdeployment/conditions_test.go | 6 +++--- internal/utils/controller/appdeployment/job_test.go | 10 +++++----- internal/utils/controller/cache/cache.go | 2 +- internal/utils/controller/cache/cache_test.go | 2 +- internal/utils/controller/cachekey.go | 2 +- internal/utils/controller/cachekey_test.go | 2 +- internal/utils/controller/operation/operation.go | 2 +- internal/utils/controller/operation/operation_test.go | 2 +- internal/utils/controller/operation/status.go | 2 +- internal/utils/controller/operation/status_test.go | 2 +- internal/utils/controller/requirement/status.go | 2 +- internal/utils/controller/requirement/status_test.go | 2 +- 27 files changed, 35 insertions(+), 40 deletions(-) diff --git a/internal/controller/appdeployment_adapter.go b/internal/controller/appdeployment_adapter.go index 26df5c7..d7bed0b 100644 --- a/internal/controller/appdeployment_adapter.go +++ b/internal/controller/appdeployment_adapter.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" apdutil "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) diff --git a/internal/controller/appdeployment_adapter_test.go b/internal/controller/appdeployment_adapter_test.go index 21ec534..3fd3495 100644 --- a/internal/controller/appdeployment_adapter_test.go +++ b/internal/controller/appdeployment_adapter_test.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" apdutil "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" diff --git a/internal/controller/appdeployment_controller.go b/internal/controller/appdeployment_controller.go index f7a384d..0eb2361 100644 --- a/internal/controller/appdeployment_controller.go +++ b/internal/controller/appdeployment_controller.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" apdutil "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) diff --git a/internal/controller/cache_adapter.go b/internal/controller/cache_adapter.go index ca8cfd9..8d4f808 100644 --- a/internal/controller/cache_adapter.go +++ b/internal/controller/cache_adapter.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ctrlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" diff --git a/internal/controller/cache_adapter_test.go b/internal/controller/cache_adapter_test.go index d24ae2c..d5c16bf 100644 --- a/internal/controller/cache_adapter_test.go +++ b/internal/controller/cache_adapter_test.go @@ -16,7 +16,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" ctrlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" diff --git a/internal/controller/cache_controller.go b/internal/controller/cache_controller.go index 21069d9..be073ba 100644 --- a/internal/controller/cache_controller.go +++ b/internal/controller/cache_controller.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) diff --git a/internal/controller/cache_controller_test.go b/internal/controller/cache_controller_test.go index 9b81515..03bef64 100644 --- a/internal/controller/cache_controller_test.go +++ b/internal/controller/cache_controller_test.go @@ -20,24 +20,19 @@ import ( "context" "testing" - // "testing" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" - "k8s.io/client-go/kubernetes/scheme" - + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client/fake" "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/controller/mocks" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestReconcile(t *testing.T) { diff --git a/internal/controller/operation_adapter.go b/internal/controller/operation_adapter.go index 4e49132..678a2fb 100644 --- a/internal/controller/operation_adapter.go +++ b/internal/controller/operation_adapter.go @@ -14,7 +14,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ctlrutils "github.com/Azure/operation-cache-controller/internal/utils/controller" apdutils "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" diff --git a/internal/controller/operation_adapter_test.go b/internal/controller/operation_adapter_test.go index 7a93571..a57783e 100644 --- a/internal/controller/operation_adapter_test.go +++ b/internal/controller/operation_adapter_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" adputils "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" diff --git a/internal/controller/operation_controller.go b/internal/controller/operation_controller.go index 1c16f4a..11fee5e 100644 --- a/internal/controller/operation_controller.go +++ b/internal/controller/operation_controller.go @@ -27,7 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) diff --git a/internal/controller/requirement_adapter.go b/internal/controller/requirement_adapter.go index 97ab214..1201f8d 100644 --- a/internal/controller/requirement_adapter.go +++ b/internal/controller/requirement_adapter.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ctlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" cacheutils "github.com/Azure/operation-cache-controller/internal/utils/controller/cache" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" diff --git a/internal/controller/requirement_adapter_test.go b/internal/controller/requirement_adapter_test.go index 89cffdf..8ab3abb 100644 --- a/internal/controller/requirement_adapter_test.go +++ b/internal/controller/requirement_adapter_test.go @@ -16,7 +16,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" mockpkg "github.com/Azure/operation-cache-controller/internal/mocks" ctlutils "github.com/Azure/operation-cache-controller/internal/utils/controller" oputils "github.com/Azure/operation-cache-controller/internal/utils/controller/operation" diff --git a/internal/controller/requirement_controller.go b/internal/controller/requirement_controller.go index 456aff7..ff8cd6f 100644 --- a/internal/controller/requirement_controller.go +++ b/internal/controller/requirement_controller.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) diff --git a/internal/controller/requirement_controller_test.go b/internal/controller/requirement_controller_test.go index ac7424a..c9632d7 100644 --- a/internal/controller/requirement_controller_test.go +++ b/internal/controller/requirement_controller_test.go @@ -34,7 +34,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/controller/mocks" "github.com/Azure/operation-cache-controller/internal/utils/reconciler" ) diff --git a/internal/utils/controller/appdeployment/conditions.go b/internal/utils/controller/appdeployment/conditions.go index f2cfc77..87d9613 100644 --- a/internal/utils/controller/appdeployment/conditions.go +++ b/internal/utils/controller/appdeployment/conditions.go @@ -5,10 +5,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appv1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) -func ClearConditions(ctx context.Context, appdeployment *appv1.AppDeployment) { +func ClearConditions(ctx context.Context, appdeployment *v1alpha1.AppDeployment) { // Clear all conditions appdeployment.Status.Conditions = []metav1.Condition{} } diff --git a/internal/utils/controller/appdeployment/conditions_test.go b/internal/utils/controller/appdeployment/conditions_test.go index 014763f..0d08d67 100644 --- a/internal/utils/controller/appdeployment/conditions_test.go +++ b/internal/utils/controller/appdeployment/conditions_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appv1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/Azure/operation-cache-controller/internal/utils/controller/appdeployment" ) @@ -41,8 +41,8 @@ func TestClearConditions(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - appDep := &appv1.AppDeployment{ - Status: appv1.AppDeploymentStatus{ + appDep := &v1alpha1.AppDeployment{ + Status: v1alpha1.AppDeploymentStatus{ Conditions: tt.existingConditions, }, } diff --git a/internal/utils/controller/appdeployment/job_test.go b/internal/utils/controller/appdeployment/job_test.go index 96bdadf..5415e49 100644 --- a/internal/utils/controller/appdeployment/job_test.go +++ b/internal/utils/controller/appdeployment/job_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - appv1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" "github.com/stretchr/testify/assert" batchv1 "k8s.io/api/batch/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -114,11 +114,11 @@ func TestGetProvisionJobName(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - appDeployment := &appv1.AppDeployment{ + appDeployment := &v1alpha1.AppDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: tt.appName, }, - Spec: appv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: tt.opId, }, } @@ -157,11 +157,11 @@ func TestGetTeardownJobName(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - appDeployment := &appv1.AppDeployment{ + appDeployment := &v1alpha1.AppDeployment{ ObjectMeta: metav1.ObjectMeta{ Name: tt.appName, }, - Spec: appv1.AppDeploymentSpec{ + Spec: v1alpha1.AppDeploymentSpec{ OpId: tt.opId, }, } diff --git a/internal/utils/controller/cache/cache.go b/internal/utils/controller/cache/cache.go index 0d3f973..ac5d1c8 100644 --- a/internal/utils/controller/cache/cache.go +++ b/internal/utils/controller/cache/cache.go @@ -4,7 +4,7 @@ import ( "math/rand" "time" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func RandomSelectCachedOperation(cache *v1alpha1.Cache) string { diff --git a/internal/utils/controller/cache/cache_test.go b/internal/utils/controller/cache/cache_test.go index ba57d46..b90887d 100644 --- a/internal/utils/controller/cache/cache_test.go +++ b/internal/utils/controller/cache/cache_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestRandomSelectCachedOperation(t *testing.T) { diff --git a/internal/utils/controller/cachekey.go b/internal/utils/controller/cachekey.go index e1c2a76..80ca973 100644 --- a/internal/utils/controller/cachekey.go +++ b/internal/utils/controller/cachekey.go @@ -9,7 +9,7 @@ import ( "github.com/samber/lo" corev1 "k8s.io/api/core/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) type AppCacheField struct { diff --git a/internal/utils/controller/cachekey_test.go b/internal/utils/controller/cachekey_test.go index 4d59560..787fdc8 100644 --- a/internal/utils/controller/cachekey_test.go +++ b/internal/utils/controller/cachekey_test.go @@ -7,7 +7,7 @@ import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestNewCacheKey(t *testing.T) { diff --git a/internal/utils/controller/operation/operation.go b/internal/utils/controller/operation/operation.go index de90fba..48852ac 100644 --- a/internal/utils/controller/operation/operation.go +++ b/internal/utils/controller/operation/operation.go @@ -8,7 +8,7 @@ import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) // NewOperationId generates a new operation id which is an UUID. diff --git a/internal/utils/controller/operation/operation_test.go b/internal/utils/controller/operation/operation_test.go index 6cf1ec3..d35b7d9 100644 --- a/internal/utils/controller/operation/operation_test.go +++ b/internal/utils/controller/operation/operation_test.go @@ -9,7 +9,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestNewOperationId(t *testing.T) { diff --git a/internal/utils/controller/operation/status.go b/internal/utils/controller/operation/status.go index 69868be..34de847 100644 --- a/internal/utils/controller/operation/status.go +++ b/internal/utils/controller/operation/status.go @@ -3,7 +3,7 @@ package operation import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func ClearConditions(operation *v1alpha1.Operation) { diff --git a/internal/utils/controller/operation/status_test.go b/internal/utils/controller/operation/status_test.go index f486914..670ab08 100644 --- a/internal/utils/controller/operation/status_test.go +++ b/internal/utils/controller/operation/status_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func TestConditions(t *testing.T) { diff --git a/internal/utils/controller/requirement/status.go b/internal/utils/controller/requirement/status.go index eaa5aef..9966168 100644 --- a/internal/utils/controller/requirement/status.go +++ b/internal/utils/controller/requirement/status.go @@ -3,7 +3,7 @@ package requirement import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) func ClearConditions(r *v1alpha1.Requirement) { diff --git a/internal/utils/controller/requirement/status_test.go b/internal/utils/controller/requirement/status_test.go index dadb2d3..6ac1b94 100644 --- a/internal/utils/controller/requirement/status_test.go +++ b/internal/utils/controller/requirement/status_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1alpha1 "github.com/Azure/operation-cache-controller/api/v1alpha1" + "github.com/Azure/operation-cache-controller/api/v1alpha1" ) // --- Test ClearConditions ---