Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add addoption by annotation feature #164

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

michaelhtm
Copy link
Member

@michaelhtm michaelhtm commented Nov 14, 2024

Issue #, if available:

Description of changes:
These changes introduce a new feature gate called ResourceAdoption
which allows users to provide the Read required fields in the annotation and
an empty spec, and the controller would populate the resource and adopt
from AWS

Currently we are considering two values for the adoption-policy annotation,
one being adopt, which will just try to adopt a resource, and if not found,
keep trying until a resource to adopt exists, or adopt-or-create which will
be able to create a resource if adoption fails because resource doesn't exist.

Before we support adopt-or-create we need a solution in code-gen
where we change how we handle the PopulateResourceFromAnnotation
which currently only allows the population of fields that are
required for a readOne operation, and they happen to be all scalar
fields (besides ARN, but we have a way of handling that), but the
required fields for create would need to be sometimes structs,
and this would require users to provide values in form of maps
eg.
Creating an EKS cluster requires a ResourceVPCConfig, which is a
struct that contains subnetIDs etc.
We can have a couple of ways to address this.

  1. Accept these values in the spec, and return terminal error when
    we attempt a create and the create required fields are not provided
  2. Accept these values in the adoption-fields annotation. This would
    need a code-gen change to allow reading from structs and assigning
    fields. but it would also make the annotation easy to make mistakes
    with when using yaml

Here's an example for cluster:

apiVersion: eks.services.k8s.aws/v1alpha1
kind: Cluster
metadata:
  name: my-cluster
  annotations:
    services.k8s.aws/adoption-policy: "adopt"
    services.k8s.aws/adoption-fields: | 
        {
          "name": "my-cluster"
        }

Here's another one to adopt a nodegroup

apiVersion: eks.services.k8s.aws/v1alpha1
kind: NodeGroup
metadata:
  name: my-ng
  annotations:
    services.k8s.aws/adoption-policy: "adopt"
    services.k8s.aws/adoption-fields: | 
        {
          "name": "ng-12324",
          "clusterName": "my-cluster"
        }

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow bot requested review from a-hilaly and jlbutler November 14, 2024 00:13
These changes introduce a new feature gate called `ForceAdoptResources`
which allows users to provide the read required fields in the annotation
and an empty spec, and the controller would populate the resource
and adopt from AWS
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this Mr Michael! i left a few comments below

pkg/featuregate/features.go Outdated Show resolved Hide resolved
pkg/runtime/util.go Outdated Show resolved Hide resolved
pkg/runtime/util.go Outdated Show resolved Hide resolved
pkg/runtime/util.go Outdated Show resolved Hide resolved
Comment on lines +445 to +446
//
// NOTE(michaelhtm): Done, tnx :)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

pkg/runtime/reconciler.go Outdated Show resolved Hide resolved
pkg/runtime/reconciler.go Outdated Show resolved Hide resolved
pkg/runtime/util.go Show resolved Hide resolved
pkg/runtime/reconciler.go Outdated Show resolved Hide resolved
pkg/runtime/reconciler.go Outdated Show resolved Hide resolved
This change will allow us to support an `adopt-or-create` policy
in the future, where the controller will create the resource when
the resource does not exist and can't be adopted.

Before we support `adopt-or-create` we need a solution in code-gen
where we change how we handle the `PopulateResourceFromAnnotation`
which currently only allows the population of fields that are
required for a readOne operation, and they happen to be all scalar
fields (besides ARN, but we have a way of handling that), but the
required fields for create would need to be sometimes structs,
and this would require users to provide values in form of maps
eg.
Creating an EKS cluster requires a ResourceVPCConfig, which is a
struct that contains subnetIDs etc.
We can have a couple of ways to address this.
1. Accept these values in the spec, and return terminal error when
   we attempt a create and the create required fields are not provided
2. Accept these values in the `adoption-fields` annotation. This would
   need a code-gen change to allow reading from structs and assigning
   fields. but it would also make the annotation easy to make mistakes
   with when using yaml
Copy link

ack-prow bot commented Nov 29, 2024

@michaelhtm: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
verify-attribution 4d78380 link false /test verify-attribution
ecr-controller-test 4d78380 link true /test ecr-controller-test
s3-controller-test 4d78380 link true /test s3-controller-test
iam-controller-test 4d78380 link true /test iam-controller-test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this Michael! merging to see how tests are doing on code-gen
/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2024
Copy link

ack-prow bot commented Dec 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-hilaly, michaelhtm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow ack-prow bot added the approved label Dec 2, 2024
@a-hilaly a-hilaly merged commit a6b0014 into aws-controllers-k8s:main Dec 2, 2024
1 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants