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

✨ Add PullSecret controller to save pull secret data locally #1322

Merged
merged 2 commits into from
Oct 8, 2024

Conversation

anik120
Copy link
Contributor

@anik120 anik120 commented Sep 30, 2024

RFC: https://docs.google.com/document/d/1BXD6kj5zXHcGiqvJOikU2xs8kV26TPnzEKp6n7TKD4M/edit#heading=h.x3tfh25grvnv

Description

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@anik120 anik120 requested a review from a team as a code owner September 30, 2024 16:12
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 30, 2024
Copy link

netlify bot commented Sep 30, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 018510e
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/6705361773e3d00008a5194e
😎 Deploy Preview https://deploy-preview-1322--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 44.85981% with 59 lines in your changes missing coverage. Please review.

Project coverage is 74.99%. Comparing base (dd1730a) to head (018510e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/manager/main.go 40.74% 26 Missing and 6 partials ⚠️
internal/controllers/pull_secret_controller.go 41.86% 21 Missing and 4 partials ⚠️
internal/rukpak/source/containers_image.go 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1322      +/-   ##
==========================================
- Coverage   76.42%   74.99%   -1.44%     
==========================================
  Files          41       42       +1     
  Lines        2431     2507      +76     
==========================================
+ Hits         1858     1880      +22     
- Misses        400      443      +43     
- Partials      173      184      +11     
Flag Coverage Δ
e2e 56.84% <27.10%> (-1.62%) ⬇️
unit 52.85% <24.29%> (-0.88%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anik120
Copy link
Contributor Author

anik120 commented Oct 1, 2024

Where the PR stands so far:

  • On start up:
.
.
I1001 16:50:17.917567       1 controller.go:217] "Starting workers" controller="secret" controllerGroup="" controllerKind="Secret" worker count=1
.
.
  • On creation of a secret, the namespace/name for which is passed via the flag:
I1001 16:51:08.001691       1 secret_syncer_controller.go:103] "Saved Secret data locally" controller="secret" controllerGroup="" controllerKind="Secret" Secret="olmv1-system/pull-secret" namespace="olmv1-system" name="pull-secret" reconcileID="fe0d20fe-17dd-4af7-9a76-d433de66ed3a"
  • The data in the file system:
$ cat /tmp/operator-controller/auth.json
{".dockerconfigjson":"{\n  \"auths\": {\n    \"registry.build09.ci.openshift.org\": {\n      \"auth\": \"dXNlcjp..

More details about this file here

  • On deletion of the Secret:
I1001 17:03:31.719907       1 secret_syncer_controller.go:54] "Secret" controller="secret" controllerGroup="" controllerKind="Secret" Secret="olmv1-system/pull-secret" namespace="olmv1-system" name="pull-secret" reconcileID="ea3490a2-fa78-46d4-a396-a10cad77dddc" pull-secret="in namespace" olmv1-system="deleted."
I1001 17:03:31.720283       1 secret_syncer_controller.go:109] "Emptying local auth file." controller="secret" controllerGroup="" controllerKind="Secret" Secret="olmv1-system/pull-secret" namespace="olmv1-system" name="pull-secret" reconcileID="ea3490a2-fa78-46d4-a396-a10cad77dddc"
I1001 17:03:31.720629       1 secret_syncer_controller.go:116] "Auth file emptied successfully" controller="secret" controllerGroup="" controllerKind="Secret" Secret="olmv1-system/pull-secret" namespace="olmv1-system" name="pull-secret" reconcileID="ea3490a2-fa78-46d4-a396-a10cad77dddc" file="/tmp/operator-controller/auth.json"
  • Content in the file
$ cat /tmp/operator-controller/auth.json
$

cmd/manager/main.go Outdated Show resolved Hide resolved
@skattoju
Copy link
Contributor

skattoju commented Oct 1, 2024

fixes #1015

cmd/manager/main.go Outdated Show resolved Hide resolved
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 3, 2024
@@ -101,6 +105,7 @@ func main() {
flag.StringVar(&cachePath, "cache-path", "/var/cache", "The local directory path used for filesystem based caching")
flag.BoolVar(&operatorControllerVersion, "version", false, "Prints operator-controller version information")
flag.StringVar(&systemNamespace, "system-namespace", "", "Configures the namespace that gets used to deploy system resources.")
flag.StringVar(&globalPullSecret, "global-pull-secret", "", "The namespace/name of the global pull secret that is going to be used to pull bundle images.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as a thing to note, there is a flag.Var() method that would allow us to implement a custom flag value with custom logic for handling how it is set, including validations.

I did something similar to this in kapp back when we were contributing preflight checks: https://github.com/carvel-dev/kapp/blob/ca6887d26d782636fe62a2b3f3bbbf5c91a965f3/pkg/kapp/preflight/registry.go#L64-L97

Might be overkill for this particular case, but this may be a good way to handle any custom flag validations we want in the future

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 5, 2024
@anik120 anik120 force-pushed the secret-controller branch 2 times, most recently from 60a4c92 to ec18c90 Compare October 7, 2024 13:07
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 7, 2024
@anik120 anik120 changed the title ✨ Add SecretSyncer controller to save pull secret data locally ✨ Add PullSecret controller to save pull secret data locally Oct 7, 2024
cmd/manager/main.go Outdated Show resolved Hide resolved
Comment on lines +153 to +162
cacheOptions.ByObject[&corev1.Secret{}] = crcache.ByObject{
Namespaces: map[string]crcache.Config{
globalPullSecretKey.Namespace: {
LabelSelector: k8slabels.Everything(),
FieldSelector: fields.SelectorFromSet(map[string]string{
"metadata.name": globalPullSecretKey.Name,
}),
},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this also override the configuration for secrets in the systemNamespace? IIUC we want to make sure we have access to all the release secrets that get created by the secret driver we use for partitioning helm release secrets for larger bundles.

Copy link
Contributor

Choose a reason for hiding this comment

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

Approved pending an answer to this

Copy link
Member

Choose a reason for hiding this comment

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

Dirty secret: iirc, the release secret driver is still a live client. So checking whether that is working won't actually tell you anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I don't actually see any configuration for secretes in the systemNamespace. There's configuration for &ocv1alpha1.ClusterExtension{} and &catalogd.ClusterCatalog{}, but nothing for Secrets.

everettraven
everettraven previously approved these changes Oct 7, 2024
@everettraven everettraven dismissed their stale review October 7, 2024 18:11

Dismissing because I had a question I forgot about that should be verified

if systemNamespace == "" {
systemNamespace = podNamespace()
}

setupLog.Info("set up manager")
cacheOptions := crcache.Options{
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: If you can add some comments around what the below code doing it will add a lot to the readability of the code.

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'm not convinced any further documentation is necessary. The crcache.Options struct is pretty well documented. Once the reader understands what the controller-runtime cache does and what Options can be used to configure, the code reads "configuring caching options for the objects we own + additional object Secret in a specific namespace".

everettraven
everettraven previously approved these changes Oct 8, 2024
@anik120 anik120 enabled auto-merge October 8, 2024 11:29
@anik120 anik120 disabled auto-merge October 8, 2024 11:29
@anik120 anik120 added this pull request to the merge queue Oct 8, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 8, 2024
* ✨ Add PullSecret controller to save pull secret data locally

RFC: https://docs.google.com/document/d/1BXD6kj5zXHcGiqvJOikU2xs8kV26TPnzEKp6n7TKD4M/edit#heading=h.x3tfh25grvnv

* main.go: improved cache configuration for watching pull secret

Signed-off-by: Joe Lanford <[email protected]>

---------

Signed-off-by: Joe Lanford <[email protected]>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 8, 2024
@LalatenduMohanty LalatenduMohanty added this pull request to the merge queue Oct 8, 2024
Merged via the queue into operator-framework:main with commit f35edf6 Oct 8, 2024
16 of 18 checks passed
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.

8 participants