Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Metrics-server should not create or addopt kube-system namespace. #4421

Conversation

adduarte
Copy link

@adduarte adduarte commented May 8, 2022

If the metric server creates or addopts the kube-system namespace,
it will be marked for deletion whenever the metric-server package is
deleted. kube-system namespace deletion is not allowed.

Fixes vmware-tanzu/tanzu-framework#1708

Describe testing done for PR

Special notes for your reviewer

@adduarte adduarte requested a review from a team as a code owner May 8, 2022 07:52
@github-actions github-actions bot added the owner/packages Work executed by a package's maintainer label May 8, 2022
@adduarte adduarte marked this pull request as draft May 8, 2022 07:53
@@ -12,7 +12,7 @@ daemonset:
updateStrategy: null
metricsServer:
namespace: null
createNamespace: true
createNamespace: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Couple of scenarios we need to handle:

  1. User giving createNamespace: true and namespace: kube-system - In this case lets not create namespace
  2. Upgrade: User upgrades the package but has older data values i.e. User in their data values has createNamespace: true. So even though package defaults are changed the user has createNamespace: true and hence during delete it will attempt to delete the namespace. Lets also add https://carvel.dev/kapp/docs/v0.46.0/apply/#kappk14siodelete-strategy delete-strategy:orphan in the namespace to prevent deletion of namespace

Copy link
Author

@adduarte adduarte May 19, 2022

Choose a reason for hiding this comment

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

namespace creation is handled by kapp-controller. I don't think we can do much here to prevent the creation or adoption of the namespace when the user intentionally sets createNamespace: true.
However adding delete-strategy:orphan to the namespace will mitigate this as well.

Copy link
Author

Choose a reason for hiding this comment

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

It looks like this behavior has been fixed in carvel-dev/kapp#468

see discussion here: https://kubernetes.slack.com/archives/C02GY94A8KT/p1645018465370589
There is a request to add a feature to kapp to prevent a package from taking ownership: carvel-dev/kapp-controller#523

and the fix is referenced there.
looks like fix should be available as of kapp v0.47.0

Copy link
Author

Choose a reason for hiding this comment

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

for deployments that use older kapp-controller the best approach will be to add https://carvel.dev/kapp/docs/v0.46.0/apply/#kappk14siodelete-strategy delete-strategy:orphan, and modify the values.yaml as suggested in this pr

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Lets add https://carvel.dev/kapp/docs/v0.46.0/apply/#kappk14siodelete-strategy delete-strategy:orphan for older kapp-controller deployments
  2. Can we add a check here https://github.com/vmware-tanzu/community-edition/blob/main/addons/packages/metrics-server/0.5.1/bundle/config/overlays/overlay-namespace.yaml#L12
    #@ if data.values.metricsServer.createNamespace and data.values.namespace != "kube-system":
    To prevent even creating namespace if kube-system is given ?

Copy link
Author

Choose a reason for hiding this comment

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

sounds like a good plan

Copy link
Author

Choose a reason for hiding this comment

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

added check of != "kube-system" to 0.5.1,
added orphaned label to kube-system namespace on 0.4.1,
Not sure if this is the correct way to add the orphan label.

@adduarte adduarte force-pushed the metrics-package-namespace-creation branch from 5af8563 to 1103b72 Compare May 27, 2022 15:53
@adduarte adduarte requested a review from shyaamsn May 27, 2022 15:55
@adduarte adduarte force-pushed the metrics-package-namespace-creation branch from 1103b72 to 72f3515 Compare June 2, 2022 01:07
@adduarte
Copy link
Author

adduarte commented Jun 2, 2022

The latest commit only sets createNamespace: false.
Since the change will be included weather or not we use the delete-strategy:orphan label, it is a good place to start.
We can add other changes as follow up prs if we find it is not enough

If the metric server creates or addopts the kube-system namespace,
it will be marked for deletion whenever the metric-server package is
deleted. kube-system namespace deletion is not allowed.

set createNamespace to default false

Fixes 1708
@adduarte adduarte force-pushed the metrics-package-namespace-creation branch from 72f3515 to 5ba9794 Compare June 2, 2022 01:20
@adduarte
Copy link
Author

adduarte commented Jun 6, 2022

In order to move forward we will scale down this patch to only fix the incorrect settings in metrics-server package bundle.
A different patch in tanz-framwork/addons/a will be used to correct any deployments which have the kube-system namespace marked with the kapp-controller annotations.

@adduarte adduarte marked this pull request as ready for review June 6, 2022 17:48
@adduarte adduarte marked this pull request as draft June 6, 2022 18:31
@adduarte
Copy link
Author

selected this as a better solutionhttps://github.com//pull/4724

@adduarte adduarte closed this Jun 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-not-required owner/packages Work executed by a package's maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

metrics-package should not have createNamespace:true for kube-system
3 participants