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

fix: don't delete coredns unless previously managed by kamaji #527

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

Marlinc
Copy link
Contributor

@Marlinc Marlinc commented Aug 7, 2024

This is still a draft

Copy link

netlify bot commented Aug 7, 2024

Deploy Preview for kamaji-documentation canceled.

Name Link
🔨 Latest commit 2492801
🔍 Latest deploy log https://app.netlify.com/sites/kamaji-documentation/deploys/66c727341cc94d00089fbef7

@prometherion
Copy link
Member

Several adopters reported this, and it's a neat feature/bug.

I'll be happy to have a different approach, tho: the Resource Handler is an interface with the following functions.

type Resource interface {
Define(context.Context, *kamajiv1alpha1.TenantControlPlane) error
ShouldCleanup(*kamajiv1alpha1.TenantControlPlane) bool
CleanUp(context.Context, *kamajiv1alpha1.TenantControlPlane) (bool, error)
CreateOrUpdate(context.Context, *kamajiv1alpha1.TenantControlPlane) (controllerutil.OperationResult, error)
GetName() string
ShouldStatusBeUpdated(context.Context, *kamajiv1alpha1.TenantControlPlane) bool
UpdateTenantControlPlaneStatus(context.Context, *kamajiv1alpha1.TenantControlPlane) error
}

The function ShouldCleanup is the one responsible for deleting the CoreDNS, as well as other add-ons.

func (c *CoreDNS) ShouldCleanup(tcp *kamajiv1alpha1.TenantControlPlane) bool {
return tcp.Spec.Addons.CoreDNS == nil
}

For the given CoreDNS, we're just checking if the Specification addons are set to nil, but this is not efficient and not idempotent.

Since the TenantControlPlane API is storing the status, we could rely on a different condition here, such as:

  return tcp.Spec.Addons.CoreDNS == nil && tcp.Status.Addons.CoreDNS.Enabled

The said condition should be true when CoreDNS is disabled in the spec, but the status still reports an enabled CoreDNS deployment.

Upon completion of the deletion here with an Updated resource, a status update is performed, meaning we're ending up with the correct reporting

func (c *CoreDNS) UpdateTenantControlPlaneStatus(_ context.Context, tcp *kamajiv1alpha1.TenantControlPlane) error {
tcp.Status.Addons.CoreDNS.Enabled = tcp.Spec.Addons.CoreDNS != nil
tcp.Status.Addons.CoreDNS.LastUpdate = metav1.Now()
return nil
}

The same logic could be used for the other addons, maybe we could have some trouble with the konnectivity one since it is much more complicated.

@Marlinc Marlinc force-pushed the coredns branch 2 times, most recently from 92914e0 to 9af6d24 Compare August 8, 2024 14:48
Copy link
Member

@prometherion prometherion left a comment

Choose a reason for hiding this comment

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

About the maps, you can take advantage of the utilities.MergeMaps function:

e.g.:

d.SetLabels(utilities.MergeMaps(d.GetLabels(), map[string]string{"constants.ProjectNameLabelKey": constants.ProjectNameLabelValue}))

It must be applied to all the objects, but it's going to be a one-liner and much easier to read, IMO.

internal/resources/addons/coredns.go Outdated Show resolved Hide resolved
Copy link
Member

@prometherion prometherion left a comment

Choose a reason for hiding this comment

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

LGTM, feel free to convert it to Ready for review so we can get this merged

@prometherion prometherion marked this pull request as ready for review September 6, 2024 06:15
@prometherion prometherion changed the title fix: don't delete coredns if unless previously managed by kamaji fix: don't delete coredns unless previously managed by kamaji Sep 6, 2024
@prometherion prometherion merged commit 62b05ed into clastix:master Sep 6, 2024
10 checks passed
prometherion added a commit to prometherion/kamaji that referenced this pull request Sep 7, 2024
A bug has been introduced with clastix#527 which doesn't handle properly all
the required business logic, such as the application of customised
labels, as well as the handling of the controller Resource.

Signed-off-by: Dario Tranchitella <dario@tranchitella.eu>
prometherion added a commit to prometherion/kamaji that referenced this pull request Sep 7, 2024
A bug has been introduced with clastix#527 which doesn't handle properly all the required business logic, such as the application of customised labels, as well as the handling of the controller Resource.

Signed-off-by: Dario Tranchitella <dario@tranchitella.eu>
prometherion added a commit that referenced this pull request Sep 7, 2024
A bug has been introduced with #527 which doesn't handle properly all the required business logic, such as the application of customised labels, as well as the handling of the controller Resource.

Signed-off-by: Dario Tranchitella <dario@tranchitella.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants