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

[Spike] Fix controller generating cilium manifests with registry mirror #7139

Conversation

cxbrowne1207
Copy link
Member

@cxbrowne1207 cxbrowne1207 commented Dec 6, 2023

Issue #, if available:

Description of changes:
The CNI reconciler fails to generate cilium manifests in an airgapped environment because it tries to fetch the image from public.ecr.aws instead of the registry mirror. This is because the registry mirror for the helm executable reference in the cilium templater is never set when managing a cluster using FLC, so when generating the manifests helm , the logic that replaces the host in the image uri is skipped

This PR addresses the issue by enabling the controller to handle helm charts when reconciling the CNI is to construct the Helm instance in the controller. Instead of depending directly on the Helm, we can inject a HelmFactory to the cilium templater. We can then use the HelmFactory to create an instance of Helm with a registry mirror configuration if one is defined on the Cluster object.

Testing (if applicable):

Documentation added/planned (if applicable):

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@eks-distro-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from cxbrowne1207. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@eks-distro-bot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@eks-distro-bot eks-distro-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 6, 2023
@cxbrowne1207 cxbrowne1207 force-pushed the fix-airgapped-cilium-controller-upgrade branch from 5494db2 to fb6fcd0 Compare December 7, 2023 23:12
@@ -112,6 +127,20 @@ func WithPolicyAllowedNamespaces(namespaces []string) ManifestOpt {
}
}

func (t *Templater) registryLogin(ctx context.Context, helm Helm, spec *cluster.Spec) error {
Copy link
Member

Choose a reason for hiding this comment

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

looks like this "t" is not used, it can be a function instead of a method of Templater

r := registrymirror.FromCluster(spec.Cluster)
helm := t.helmFactory.GetInstance(executables.WithRegistryMirror(r))

if spec.Cluster.Spec.RegistryMirrorConfiguration != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This if check is duplicated in registryLogin function

}

func (f *HelmFactory) GetInstance(opts ...executables.HelmOpt) *executables.Helm {
f.mu.Lock()
Copy link
Member

Choose a reason for hiding this comment

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

Curious, do we really need a lock here?

func (f *Factory) WithHelmFactory(opts ...executables.HelmOpt) *Factory {
f.WithExecutableBuilder()

f.buildSteps = append(f.buildSteps, func(ctx context.Context) error {
Copy link
Member

Choose a reason for hiding this comment

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

Overall, factory is not really a preferred abstract in golang. As we have adopted it, we should try not making it more complicated.

This method introduces something feels like "nested factory", which makes the abstract harder to understand. I believe we can achieve the target without this "helmFactory"

@cxbrowne1207 cxbrowne1207 changed the title Fix controller generating cilium manifests with registry mirror [Concept PR] Fix controller generating cilium manifests with registry mirror Dec 12, 2023
@cxbrowne1207 cxbrowne1207 changed the title [Concept PR] Fix controller generating cilium manifests with registry mirror [Spike] Fix controller generating cilium manifests with registry mirror Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants