Skip to content

Commit

Permalink
Fix EKS Cluster conversion by injecting index key when list
Browse files Browse the repository at this point in the history
Manual cherry pick of crossplane-contrib#1669

Signed-off-by: Hasan Turken <turkenh@gmail.com>
  • Loading branch information
turkenh committed Feb 7, 2025
1 parent d380e1d commit c14e716
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
35 changes: 33 additions & 2 deletions config/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,41 @@ func configureSingletonListAPIConverters(r *config.Resource) error {
// because the controller reconciles on the API version with the singleton list API,
// 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",
// <nil>: 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",
},
},
}))
}

r.Conversions = []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...)}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/aws/smithy-go v1.20.2
github.com/crossplane/crossplane-runtime v1.16.0-rc.2.0.20240510094504-3f697876fa57
github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79
github.com/crossplane/upjet v1.4.1-0.20240612123927-37c7f4e91d57
github.com/crossplane/upjet v1.4.1-0.20250207082618-16771915af9e
github.com/go-ini/ini v1.46.0
github.com/google/go-cmp v0.6.0
github.com/hashicorp/awspolicyequivalence v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ github.com/crossplane/crossplane-runtime v1.16.0-rc.2.0.20240510094504-3f697876f
github.com/crossplane/crossplane-runtime v1.16.0-rc.2.0.20240510094504-3f697876fa57/go.mod h1:Pz2tdGVMF6KDGzHZOkvKro0nKc8EzK0sb/nSA7pH4Dc=
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.20240612123927-37c7f4e91d57 h1:hyKXccOb8BepVJj79KsvwYsid5Lhlr2DojO29Sqi+rw=
github.com/crossplane/upjet v1.4.1-0.20240612123927-37c7f4e91d57/go.mod h1:wkdZf/Cvhr6PI30VdHIOjg4dX39Z5uijqnLWFk5PbGM=
github.com/crossplane/upjet v1.4.1-0.20250207082618-16771915af9e h1:BvV3I9iao6YURrAie/VQfJ4Z5AwKlNvEhe+4Vt2ugdM=
github.com/crossplane/upjet v1.4.1-0.20250207082618-16771915af9e/go.mod h1:wkdZf/Cvhr6PI30VdHIOjg4dX39Z5uijqnLWFk5PbGM=
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=
Expand Down

0 comments on commit c14e716

Please sign in to comment.