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

LOG-4612: Service/secret is not deleted when the inputs.receiver.http is removed #2216

Merged
merged 1 commit into from Nov 6, 2023

Conversation

Clee2691
Copy link
Contributor

Description

This PR addresses removing stale HTTP input services when the ClusterLogForwarder (CLF) is modified.

Originally when the inputs.receiver.http was removed from the CLF and updated, NOT deleted and recreated, any previously defined HTTP input services were not garbage collected.

The approach was to label all HTTP input services with http-input-service and upon CLF reconciliation, check if the service is defined in the CLF as well as if the reconciling CLF owns the specific service. If the service is not defined, remove it.

/cc @syedriko @vparfonov
/assign @jcantrill

Links

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Oct 18, 2023
@openshift-ci-robot
Copy link

openshift-ci-robot commented Oct 18, 2023

@Clee2691: This pull request references LOG-4612 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "4.8.0" version, but no target version was set.

In response to this:

Description

This PR addresses removing stale HTTP input services when the ClusterLogForwarder (CLF) is modified.

Originally when the inputs.receiver.http was removed from the CLF and updated, NOT deleted and recreated, any previously defined HTTP input services were not garbage collected.

The approach was to label all HTTP input services with http-input-service and upon CLF reconciliation, check if the service is defined in the CLF as well as if the reconciling CLF owns the specific service. If the service is not defined, remove it.

/cc @syedriko @vparfonov
/assign @jcantrill

Links

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.

@Clee2691
Copy link
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 18, 2023
@Clee2691
Copy link
Contributor Author

/retest

@@ -93,6 +95,18 @@ func (clusterRequest *ClusterLoggingRequest) CreateOrUpdateCollection() (err err
return err
}

var httpInputs []string
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this newly added code into ReconcileInputServices(), since what it is doing is reconciling input services and as it is, it breaks the pattern in this function of a sequence of Reconcile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wasn't new code, I just moved it around as it was later in this function. However, I have now moved this to where I think the appropriate location should be.

if input.Receiver != nil && input.Receiver.HTTP != nil {
if err := clusterRequest.RemoveInputService(input.Name); err != nil {
// Find all http input services by label
labelSelector, _ := labels.Parse("component=http-input-service")
Copy link
Contributor

Choose a reason for hiding this comment

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

labelSelector, _ := labels.Parse("component=http-input-service")
&client.ListOptions{LabelSelector: labelSelector}

can be lifted to the package level as they don't depend on anything inside this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this to k8shandler/service.go and made it more generic so it can be reused in the future.

@@ -60,6 +60,8 @@ func ReconcileInputService(er record.EventRecorder, k8sClient client.Client, nam
constants.AnnotationServingCertSecretName: certSecretName,
}

desired.Labels["component"] = "http-input-service"
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to make "component" and "http-input-service" constants and use them here and in labels.Parse().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -93,6 +95,18 @@ func (clusterRequest *ClusterLoggingRequest) CreateOrUpdateCollection() (err err
return err
}

var httpInputs []string
Copy link
Contributor

Choose a reason for hiding this comment

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

httpInputs := sets.NewString()
...
httpInputs.Insert(input.Name)

? Make the collection of HTTP inputs a set from the start and avoid copying in RemoveInputServices()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Find all http input services by label
labelSelector, _ := labels.Parse("component=http-input-service")
httpServices := corev1.ServiceList{}
if err := clusterRequest.Client.List(context.TODO(), &httpServices, &client.ListOptions{LabelSelector: labelSelector}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it's possible, but can we include the owner reference into the query so we only get services owned by currOwner and with "component=http-input-service" label?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it is not possible to query on OwnerRefs

@@ -40,3 +43,13 @@ func (clusterRequest *ClusterLoggingRequest) RemoveInputService(serviceName stri

return nil
}

// GetServiceList returns a list of services based on a key/value label
func (clusterRequest *ClusterLoggingRequest) GetServiceList(key string, val string) (*core.ServiceList, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're only going to be looking at the services owned by a specific CLF, would it make sense to query here only for services in the same namespace as the CLF?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that is a good idea so as to reduce the number of services listed. I will make the change.

@syedriko
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 19, 2023
Copy link
Contributor

@jcantrill jcantrill left a comment

Choose a reason for hiding this comment

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

/approve

@jcantrill
Copy link
Contributor

holding for 5.8 z-stream

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 19, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Clee2691, jcantrill

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 19, 2023
@Clee2691
Copy link
Contributor Author

/retest

2 similar comments
@Clee2691
Copy link
Contributor Author

/retest

@Clee2691
Copy link
Contributor Author

/retest

@jcantrill
Copy link
Contributor

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 6, 2023
Copy link
Contributor

openshift-ci bot commented Nov 6, 2023

@Clee2691: all tests passed!

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.

@openshift-merge-bot openshift-merge-bot bot merged commit f4f0a95 into openshift:master Nov 6, 2023
10 checks passed
@Clee2691
Copy link
Contributor Author

/cherry-pick release-5.8

@openshift-cherrypick-robot

@Clee2691: new pull request created: #2273

In response to this:

/cherry-pick release-5.8

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. release/5.8
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants