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

Remove usage of ES ConfigMap and PublicCertSecret #2954

Merged
merged 14 commits into from
Dec 11, 2023

Conversation

Josh-Tigera
Copy link
Contributor

@Josh-Tigera Josh-Tigera commented Oct 27, 2023

These resources are no longer used now that Linseed has taken over this functionality

This has a companion commit in Calico Enterprise here

Description

For PR author

  • Tests for change.
    - [ ] If changing pkg/apis/, run make gen-files
    - [ ] If changing versions, run make gen-versions

For PR reviewers

A note for code reviewers - all pull requests must have the following:

  • Milestone set according to targeted release.
  • Appropriate labels:
    • kind/bug if this is a bugfix.
    • kind/enhancement if this is a a new feature.
    • enterprise if this PR applies to Calico Enterprise only.

@@ -227,10 +225,6 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
}
}

if err = utils.AddConfigMapWatch(c, relasticsearch.ClusterConfigConfigMapName, common.OperatorNamespace(), &handler.EnqueueRequestForObject{}); err != nil {
Copy link
Member

@caseydavenport caseydavenport Oct 30, 2023

Choose a reason for hiding this comment

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

I see you removed the Watch here, but the code below still uses the configmap.

Josh: Apparently I can modify other people's comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah you're right, this is the controller that writes it but I removed the watch since I didn't see any reads. I suppose we want to rectify any changes made to it as quickly as possible. I'll add some tests for these cases.

Copy link
Member

Choose a reason for hiding this comment

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

Josh: Apparently I can modify other people's comments?

😆

pkg/render/fluentd.go Outdated Show resolved Hide resolved
VolumeMounts: c.eksLogForwarderVolumeMounts(),
}

initContainer.Env = append(initContainer.Env, envVars...)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this - this is appending envVars onto envVars, is it not?

c.cfg.ESClusterConfig.Replicas(), c.cfg.ESClusterConfig.Shards())
container := c.intrusionDetectionControllerContainer()

envVars := []corev1.EnvVar{
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there's any need to keep these appended separately from the other env vars defined in intrustionDetectionControllerContainer()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed and this was a change I already had in my next set of changes to be pushed while I was fixing some issues I found once I loaded my images into a cluster.

},
}

container.Env = append(container.Env, envVars...)
Copy link
Member

Choose a reason for hiding this comment

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

I think throughout we should clean up this split env declaration - it's a bit confusing the way this is laid out here.

  • Define envVars
  • Create a container with a separate set of hard-coded env vars
  • Append the previously created env vars to the container's env.

We should just be able to define all of the env vars in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed that's what I have in my current iteration.

relasticsearch.ElasticIndexSuffixEnvVar(c.cfg.ClusterConfig.ClusterName()),
}

env = append(env, esEnvVars...)
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to define the intermediate variable

env = append(env, []corev1.EnvVar{
  relasticsearch.ElasticCAEnvVar(c.SupportedOSType()),
  . . .
})

pkg/render/manager_test.go Outdated Show resolved Hide resolved
pkg/render/manager_test.go Outdated Show resolved Hide resolved
if isManagedCluster {
if esClusterConfig.ClusterName() == render.DefaultElasticsearchClusterName {
err = fmt.Errorf("Elasticsearch cluster name must be non-default value in managed clusters")
r.status.SetDegraded(operatorv1.InvalidConfigurationError, "", err, reqLogger)
Copy link
Member

@caseydavenport caseydavenport Nov 21, 2023

Choose a reason for hiding this comment

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

This is an interesting new assertion - any background on this one? It seems safe to me, but curious what prompted you to add it!

I do think we need a user-facing message in the SetDegraded call instead of "" though.

Also, this isn't the Elasticsearch cluster name. Rather this is the just the name of this managed cluster (which is primarily used by our elastic log ingestion pipeline).

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 came from when I initially completely removed this configmap entirely and then we talked about how it's still needed so that we can differentiate managed vs management entries in elasticsearch indices eg. *-cluster for management vs *-<managedcluster.name> for managed clusters. I added a corresponding test in intrusion_detection_controller.go for this specific case as well. I can update the msg to contain user-facing information as well as correct the wording about what the field is actually used for.

@@ -422,16 +425,6 @@ func (r *ReconcileIntrusionDetection) Reconcile(ctx context.Context, request rec
return reconcile.Result{}, err
}

esgwCertificate, err := certificateManager.GetCertificate(r.client, relasticsearch.PublicCertSecret, common.OperatorNamespace())
Copy link
Member

Choose a reason for hiding this comment

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

From what I can tell, intrusion-detection-controller is one of the few managed cluster components that still talks directly to elasticsearch via es-gateway.

It does talk to Linseed in most codepaths, but when searching for security events it seems it still talks to ES.

return reconcile.Result{}, nil
var clusterConfig *relasticsearch.ClusterConfig
// We only require Elastic cluster configuration when Kibana is enabled. We infer whether Kibana is enabled by checking
// FIPS configuration mode and multi-tenancy mode. See manager.go function kibanaEnabled for more details.
Copy link
Member

Choose a reason for hiding this comment

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

We should probably make kibnanEnabled public and use the same implementation everywhere that we need to check if Kibana is enabled, so that they don't get out of sync.

@@ -566,6 +560,12 @@ var _ = Describe("Manager controller tests", func() {
})

Context("image reconciliation", func() {
BeforeEach(func() {
Expect(c.Create(
Copy link
Member

Choose a reason for hiding this comment

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

This can be a single line - no need to split it up.

Alternatively, we could keep this in the main BeforeEach and then any tests that need something different can just call Update in their BeforeEach to modify the installation.

relasticsearch.ElasticUserEnvVar(ElasticsearchEksLogForwarderUserSecret),
relasticsearch.ElasticPasswordEnvVar(ElasticsearchEksLogForwarderUserSecret),
relasticsearch.ElasticSchemeEnvVar(esScheme),
relasticsearch.ElasticHostEnvVar(esHost),
Copy link
Member

Choose a reason for hiding this comment

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

One to keep an eye on - once @vara2504 is done with her work for EKS log forwarder, we can remove most (all?) of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Vara sent me her PRs and these have in fact been completely removed from fluentd-docker and replaced with their Linseed counterparts.

@@ -884,6 +895,15 @@ var _ = Describe("Tigera Secure Fluentd rendering tests", func() {
}))

Expect(envs).To(ContainElement(corev1.EnvVar{Name: "EKS_CLOUDWATCH_LOG_FETCH_INTERVAL", Value: "900"}))
Expect(envs).To(ContainElements([]corev1.EnvVar{
Copy link
Member

Choose a reason for hiding this comment

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

Probably want the reverse check as well to catch any cases where there are unexpected env vars. And maybe a length check to catch bugs like the one above where we added env vars twice.

e.g.,

expected := []corev1.EnvVar{...}

Expect(envs).Should(ContainElements(expected))
Expect(expected).Should(ContainElements(envs))
Expect(envs).Should(HaveLength(len(expected))

Also, we can merge the assertion on the line right above this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced all my checks from Should(ContainElements to To(Equal so that we're more precisely checking the env variables

Copy link
Member

Choose a reason for hiding this comment

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

That's probably OK, but I specifically didn't suggest that approach because I believe it's more finicky and vulnerable to changes of variable ordering, which we don't actually care about so much.

@Josh-Tigera Josh-Tigera added release-note-not-required enterprise Feature applies to enterprise only and removed release-note-required labels Dec 1, 2023
@danudey danudey modified the milestones: v1.32.0, v1.32.1, v1.32.2 Dec 2, 2023
Copy link
Member

@caseydavenport caseydavenport left a comment

Choose a reason for hiding this comment

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

This LGTM - obviously a bit of a scary change with potential for disruption, so let's keep an eye on e2es and make sure we address any fallout in master quickly. I suspect there will be something we missed 😁

@caseydavenport
Copy link
Member

@Josh-Tigera a few conflicts to resolve, though

@Josh-Tigera Josh-Tigera merged commit 2558525 into tigera:master Dec 11, 2023
3 checks passed
@Josh-Tigera Josh-Tigera deleted the josh.cluster-config-cleanup branch December 11, 2023 15:43
@danudey danudey modified the milestones: v1.32.2, v1.32.3 Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants