diff --git a/config/registry.go b/config/registry.go index ea0f176ea9..3e9809075f 100644 --- a/config/registry.go +++ b/config/registry.go @@ -236,14 +236,44 @@ func configureSingletonListAPIConverters(r *config.Resource) error { // no need for a Terraform conversion. r.ControllerReconcileVersion = currentVer + // This block is to fix the issue described in the following PR: https://github.com/crossplane/upjet/pull/465 + // In EKS Cluster object v1beta1, for spec.vpcConfig field, we mark + // +listType as "map" and +listMapKey as "index". During conversion between + // v1beta1 to v1beta2, we convert the that field from array to object, + // losing the index field since it is not in the schema. This is fine in + // most cases since in v1beta1 of the object schema index defaults to "0", + // even though conversion doesn't output the index field in the object. + // + // However, with Server Side Apply, apparently some on the fly conversions + // happening when different managers using different api versions and losing + // index field causing unexpected merging results and drop of the whole + // spec.forProvider.vpcConfig object. This is surfaced with an error like + // below: + /// cannot patch the managed resource via server-side apply: Cluster.eks.aws.upbound.io + // "some-eks-cluster" is invalid: [spec.forProvider.vpcConfig: Invalid + // value: "null": spec.forProvider.vpcConfig in body must be of type array: "null", + // : Invalid value: "null": some validation rules were not checked because + // the object was invalid; correct the existing errors to complete validation] + var opts []conversion.SingletonListConversionOption + if r.Name == "aws_eks_cluster" { + opts = append(opts, conversion.WithConvertOptions(&conversion.ConvertOptions{ + ListInjectKeys: map[string]conversion.SingletonListInjectKey{ + "vpcConfig": { + Key: "index", + Value: "0", + }, + }, + })) + } + // assumes the first element is the identity conversion from // the default resource and removes it because we will register another // identity converter below. r.Conversions = r.Conversions[1:] r.Conversions = append([]conversion.Conversion{ conversion.NewIdentityConversionExpandPaths(conversion.AllVersions, conversion.AllVersions, conversion.DefaultPathPrefixes(), r.CRDListConversionPaths()...), - conversion.NewSingletonListConversion(conversion.AllVersions, bumped, conversion.DefaultPathPrefixes(), r.CRDListConversionPaths(), conversion.ToEmbeddedObject), - conversion.NewSingletonListConversion(bumped, conversion.AllVersions, conversion.DefaultPathPrefixes(), r.CRDListConversionPaths(), conversion.ToSingletonList), + conversion.NewSingletonListConversion(conversion.AllVersions, bumped, conversion.DefaultPathPrefixes(), r.CRDListConversionPaths(), conversion.ToEmbeddedObject, opts...), + conversion.NewSingletonListConversion(bumped, conversion.AllVersions, conversion.DefaultPathPrefixes(), r.CRDListConversionPaths(), conversion.ToSingletonList, opts...), }, r.Conversions...) return nil diff --git a/go.mod b/go.mod index 65f3e7fbd4..b72389ad3b 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/aws/smithy-go v1.22.1 github.com/crossplane/crossplane-runtime v1.17.0 github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79 - github.com/crossplane/upjet v1.4.1-0.20250130134024-ce71033d450f + github.com/crossplane/upjet v1.4.1-0.20250206162150-1a6d69bbd22a github.com/go-ini/ini v1.46.0 github.com/google/go-cmp v0.6.0 github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.59 diff --git a/go.sum b/go.sum index 14a10a2a1c..24a6e0a71a 100644 --- a/go.sum +++ b/go.sum @@ -580,8 +580,8 @@ github.com/crossplane/crossplane-runtime v1.17.0 h1:y+GvxPT1M9s8BKt2AeZJdd2d6pg2 github.com/crossplane/crossplane-runtime v1.17.0/go.mod h1:vtglCrnnbq2HurAk9yLHa4qS0bbnCxaKL7C21cQcB/0= github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79 h1:HigXs5tEQxWz0fcj8hzbU2UAZgEM7wPe0XRFOsrtF8Y= github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79/go.mod h1:+e4OaFlOcmr0JvINHl/yvEYBrZawzTgj6pQumOH1SS0= -github.com/crossplane/upjet v1.4.1-0.20250130134024-ce71033d450f h1:4BLOlbc9bY0HDhL+2oGuKQ03gdGs1+sgd8ioP1RbXW8= -github.com/crossplane/upjet v1.4.1-0.20250130134024-ce71033d450f/go.mod h1:F2u9XwKNzxM+myfS1Opjnc6a5E1N2PC7Mytbkavawvs= +github.com/crossplane/upjet v1.4.1-0.20250206162150-1a6d69bbd22a h1:BX1cOu+WEPMWG9/qI9B4gjOMYFC82L+40PJ+7wuW94s= +github.com/crossplane/upjet v1.4.1-0.20250206162150-1a6d69bbd22a/go.mod h1:F2u9XwKNzxM+myfS1Opjnc6a5E1N2PC7Mytbkavawvs= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/dave/jennifer v1.4.1 h1:XyqG6cn5RQsTj3qlWQTKlRGAyrTcsk1kUmWdZBzRjDw=