Skip to content

Commit

Permalink
Automated Config Connector import.
Browse files Browse the repository at this point in the history
  - c13a65cfe8f8ab1c52ee091d9363d5dcb9b4643b Fix the dynamic integration test for resources overrides by Config Connector Team <[email protected]>

GitOrigin-RevId: c13a65cfe8f8ab1c52ee091d9363d5dcb9b4643b
  • Loading branch information
Config Connector Team authored and copybara-github committed Jul 6, 2023
1 parent aee4ea9 commit 203d70a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
24 changes: 1 addition & 23 deletions pkg/controller/dynamic/dynamic_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
35 changes: 0 additions & 35 deletions pkg/test/resourcefixture/contexts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 203d70a

Please sign in to comment.