From 203d70a2060ea7ba794ea3e2e894b80800f831ef Mon Sep 17 00:00:00 2001 From: Config Connector Team Date: Wed, 5 Jul 2023 22:16:56 +0000 Subject: [PATCH] Automated Config Connector import. - c13a65cfe8f8ab1c52ee091d9363d5dcb9b4643b Fix the dynamic integration test for resources overrides by Config Connector Team GitOrigin-RevId: c13a65cfe8f8ab1c52ee091d9363d5dcb9b4643b --- .../dynamic_controller_integration_test.go | 24 +------------ pkg/test/resourcefixture/contexts/register.go | 35 ------------------- 2 files changed, 1 insertion(+), 58 deletions(-) diff --git a/pkg/controller/dynamic/dynamic_controller_integration_test.go b/pkg/controller/dynamic/dynamic_controller_integration_test.go index f4e42a5e0c..145f22e757 100644 --- a/pkg/controller/dynamic/dynamic_controller_integration_test.go +++ b/pkg/controller/dynamic/dynamic_controller_integration_test.go @@ -349,29 +349,7 @@ func testUpdate(t *testing.T, testContext testrunner.TestContext, systemContext if gcpUnstruct.Object["spec"] == nil { t.Fatalf("GCP resource has a nil spec even though it was created using a resource with a non-nil spec") } - - // Do pre-actuation transform for the initialUnstruct and - // reconciledUnstruct before asserting diff result of them is contained - // in the retrieved gcpUnstruct. - // - // initialUnstruct and reconciledUnstruct contain user-facing resource - // configs that match the CRD after CRDDecorate() in resource overrides - // is applied. - // However, gcpUnstruct is the live state of the resource and only - // contains fields in the CRD before CRDDecorate() is applied. - // PreActuationTransform() turns the user-facing resource configs into - // "vanilla" configs which only contain the fields in the CRD before - // CRDDecorate() is applied and makes it comparable with the retrieved - // live state of the resource. - transformedInitialUnstruct, err := resourceContext.DoPreActuationTransformFor(initialUnstruct, systemContext.TFProvider, systemContext.SMLoader, systemContext.DCLConverter) - if err != nil { - t.Fatalf("could not do pre-actuation transfrom for initialUnstruct: %v", err) - } - transformedReconciledUnstruct, err := resourceContext.DoPreActuationTransformFor(reconciledUnstruct, systemContext.TFProvider, systemContext.SMLoader, systemContext.DCLConverter) - if err != nil { - t.Fatalf("could not do pre-actuation transfrom for reconciledUnstruct: %v", err) - } - changedFields := getChangedFields(transformedInitialUnstruct.Object, transformedReconciledUnstruct.Object, "spec") + changedFields := getChangedFields(initialUnstruct.Object, reconciledUnstruct.Object, "spec") assertObjectContains(t, gcpUnstruct.Object["spec"].(map[string]interface{}), changedFields) } diff --git a/pkg/test/resourcefixture/contexts/register.go b/pkg/test/resourcefixture/contexts/register.go index c05629e3ac..d3170625a2 100644 --- a/pkg/test/resourcefixture/contexts/register.go +++ b/pkg/test/resourcefixture/contexts/register.go @@ -29,7 +29,6 @@ import ( dcllivestate "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/dcl/livestate" dclmetadata "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/dcl/metadata" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/dcl/schema/dclschemaloader" - "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/krmtotf" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/resourceoverrides" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/servicemapping/servicemappingloader" @@ -138,17 +137,6 @@ func (rc ResourceContext) Delete(t *testing.T, u *unstructured.Unstructured, pro return terraformDelete(u, provider, c, smLoader) } -func (rc ResourceContext) DoPreActuationTransformFor(u *unstructured.Unstructured, provider *tfschema.Provider, smLoader *servicemappingloader.ServiceMappingLoader, dclConverter *dclconversion.Converter) (*unstructured.Unstructured, error) { - resource, err := unstructuredToKRMResource(rc.DCLBased, u, provider, smLoader, dclConverter) - if err != nil { - return nil, err - } - if err := resourceoverrides.Handler.PreActuationTransform(resource); err != nil { - return nil, fmt.Errorf("could not run pre-acutuation transform on resource %s: %v", u.GetName(), err) - } - return resource.MarshalAsUnstructured() -} - func terraformDelete(u *unstructured.Unstructured, provider *tfschema.Provider, c client.Client, smLoader *servicemappingloader.ServiceMappingLoader) error { ctx := context.Background() resource, liveState, err := getTerraformResourceAndLiveState(ctx, u, provider, c, smLoader) @@ -336,26 +324,3 @@ func IsNotFoundError(err error) bool { } return strings.Contains(err.Error(), "is not found") } - -func unstructuredToKRMResource(isDCLBasedResource bool, u *unstructured.Unstructured, provider *tfschema.Provider, smLoader *servicemappingloader.ServiceMappingLoader, converter *dclconversion.Converter) (*k8s.Resource, error) { - if isDCLBasedResource { - return dclUnstructuredToKRMResource(u, converter) - } - return terraformUnstructuredToKRMResource(u, provider, smLoader) -} - -func dclUnstructuredToKRMResource(u *unstructured.Unstructured, converter *dclconversion.Converter) (*k8s.Resource, error) { - resource, err := newDCLResource(u, converter) - if err != nil { - return nil, err - } - return &resource.Resource, nil -} - -func terraformUnstructuredToKRMResource(u *unstructured.Unstructured, provider *tfschema.Provider, smLoader *servicemappingloader.ServiceMappingLoader) (*k8s.Resource, error) { - resource, err := newTerraformResource(u, provider, smLoader) - if err != nil { - return nil, err - } - return &resource.Resource, nil -}