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

[aws-eks] Support object pruning #10495

Closed
1 of 2 tasks
iliapolo opened this issue Sep 23, 2020 · 1 comment · Fixed by #11932
Closed
1 of 2 tasks

[aws-eks] Support object pruning #10495

iliapolo opened this issue Sep 23, 2020 · 1 comment · Fixed by #11932
Assignees
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.

Comments

@iliapolo
Copy link
Contributor

Use Case

Currently, situations may arise that leave orphan resources. For example, consider the following manifest:

new eks.KubernetesManifest(this, 'Configs', {
  cluster,
  manifest: [
    {
      kind: 'ConfigMap',
      apiVersion: 'v1',
      metadata: {
        name: 'config1'
      },
      data: {
        foo: 'bar'
      }
    }, 
    {
      kind: 'ConfigMap',
      apiVersion: 'v1',
      metadata: {
        name: 'config2'
      },
      data: {
        hello: 'world'
      }
    }, 
  ]
})

When it is first deployed, we issue a kubectl apply command that creates both config maps.

If we now remove one config map, i.e the manifest will look like so:

new eks.KubernetesManifest(this, 'Configs', {
  cluster,
  manifest: [
    {
      kind: 'ConfigMap',
      apiVersion: 'v1',
      metadata: {
        name: 'config1'
      },
      data: {
        foo: 'bar'
      }
    } 
  ]
})

Since the CFN resource is the same, just its properties changed, an UPDATE call be executed by CFN, which will simply translate into a kubectl apply on the new manifest, which will not delete the config map that was removed from the manifest.

Proposed Solution

  • Automatically add pruning labels to all resources and use kubectl apply --prune (see pruning objects)

  • Before running kubectl apply on update, run kubectl delete on the previous manifest (available as as CFN property at invocation time)

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@iliapolo iliapolo added p1 feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 23, 2020
@github-actions github-actions bot added the @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service label Sep 23, 2020
@iliapolo iliapolo added effort/medium Medium work item – several days of effort @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service and removed @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service labels Sep 23, 2020
@iliapolo iliapolo added this to the [GA] @aws-cdk/aws-eks milestone Oct 4, 2020
@eladb eladb assigned eladb and unassigned iliapolo Dec 6, 2020
eladb pushed a commit that referenced this issue Dec 8, 2020
In order to support deletion of kubernetes manifest resources, the EKS module now automatically allocates and injects a "prune label" to all resources. This label is then passed down to `kubectl apply` with the `--prune` option so that any resources in the cluster that do not appear in the manifest will get deleted.

The `prune` option can be set to `false` (either at the `Cluster` level or at the KubernetesResource level) to disable this.

In order to avoid needing to update all tests, many of the existing tests set `prune: false` so that their outputs are not impacted.

Resolves #10495
@eladb eladb added pr/work-in-progress This PR is a draft and needs further work. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. and removed pr/work-in-progress This PR is a draft and needs further work. labels Dec 9, 2020
@mergify mergify bot closed this as completed in #11932 Dec 10, 2020
mergify bot pushed a commit that referenced this issue Dec 10, 2020
In order to support deletion of kubernetes manifest resources, the EKS module now automatically allocates and injects a "prune label" to all resources. This label is then passed down to `kubectl apply` with the `--prune` option so that any resources in the cluster that do not appear in the manifest will get deleted.

The `prune` option can be set to `false` (either at the `Cluster` level or at the KubernetesResource level) to disable this.

In order to avoid needing to update all tests, many of the existing tests set `prune: false` so that their outputs are not impacted.

Resolves #10495

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

flochaz pushed a commit to flochaz/aws-cdk that referenced this issue Jan 5, 2021
In order to support deletion of kubernetes manifest resources, the EKS module now automatically allocates and injects a "prune label" to all resources. This label is then passed down to `kubectl apply` with the `--prune` option so that any resources in the cluster that do not appear in the manifest will get deleted.

The `prune` option can be set to `false` (either at the `Cluster` level or at the KubernetesResource level) to disable this.

In order to avoid needing to update all tests, many of the existing tests set `prune: false` so that their outputs are not impacted.

Resolves aws#10495

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants