feat: add automatic imagePullSecret (dockerconfigjson) generation#257
Open
christian-deleon wants to merge 10 commits into1Password:mainfrom
Open
feat: add automatic imagePullSecret (dockerconfigjson) generation#257christian-deleon wants to merge 10 commits into1Password:mainfrom
christian-deleon wants to merge 10 commits into1Password:mainfrom
Conversation
Add ID, SectionID, and FieldType fields to ItemField. Add ItemSection struct and Sections slice to Item. Enrich FromConnectItem and FromSDKItem to populate section metadata from the respective SDK types. This metadata is needed to support Go template rendering where users can reference fields by section (e.g. .Sections.Database.username).
Add SecretTemplate struct with a Data map[string]string field and an optional Template pointer on OnePasswordItemSpec. Regenerate deepcopy methods and CRD manifests. This allows users to define Go template strings per secret key in their OnePasswordItem resources.
Add pkg/template with BuildTemplateContext and ProcessTemplate functions. BuildTemplateContext constructs a TemplateContext from a model.Item with three access patterns: .Fields (flat by label), .Sections (nested by section title), and .FieldsByID (by unique field ID). ProcessTemplate parses and executes a Go template string against the context, returning the rendered bytes.
…lers Update BuildKubernetesSecretData to accept a model.Item and optional SecretTemplate instead of decomposed fields/urls/files. When a template is provided, render each key through the Go template engine and return only the templated keys. Fall back to default field/URL/file mapping when no template is set. Thread the SecretTemplate parameter through CreateKubernetesSecretFromItem and BuildKubernetesSecretFromOnePasswordItem. The OnePasswordItem controller extracts the template from the resource spec; the deployment controller and secret update handler pass nil (no template support for annotation-based secrets). Update all existing test call sites and add template-specific unit tests covering multi-key templates, section access, hyphenated keys via index, invalid template handling, nil template fallback, and end-to-end secret creation. Add integration tests for template rendering in the controller test suite.
Document the template feature in USAGEGUIDE.md including basic usage, multiple keys, template context reference (.Fields, .Sections, .FieldsByID, index for special characters), and behaviour notes.
Add ImagePullSecretConfig struct to OnePasswordItem spec for configuring automatic dockerconfigjson generation from 1Password item fields. Users specify which fields map to registry, username, password, and email. Add BuildDockerConfigJSON function in the template package that produces properly structured .dockerconfigjson with base64-encoded auth.
Thread imagePullSecret config through CreateKubernetesSecretFromItem, BuildKubernetesSecretFromOnePasswordItem, and BuildKubernetesSecretData. When imagePullSecret is configured, the operator builds a properly formatted .dockerconfigjson from the specified 1Password fields. The controller auto-sets the secret type to kubernetes.io/dockerconfigjson when imagePullSecret is present and no type is explicitly set. Priority order: imagePullSecret > template > default field mapping.
Add Image Pull Secrets section to USAGEGUIDE.md with quick example, configuration reference, and behaviour notes.
…lSecrets for restart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ Summary
Adds
imagePullSecretconfig toOnePasswordItem, allowing the operator to automatically generate properly formattedkubernetes.io/dockerconfigjsonsecrets from 1Password item fields.Motivation: Image pull secrets require a specific
.dockerconfigjsonformat with base64-encoded auth. Currently users must either manually create these secrets or use external tooling. This feature lets the operator handle it natively by mapping 1Password fields to the required registry, username, password, and email values.Example:
Produces:
{ "auths": { "ghcr.io": { "username": "myuser", "password": "mytoken", "email": "me@example.com", "auth": "bXl1c2VyOm15dG9rZW4=" } } }What's included:
ImagePullSecretConfigtype added toOnePasswordItemSpecwith field mappings (registryField,usernameField,passwordField,emailField)BuildDockerConfigJSONbuilder inpkg/template/imagepullsecret.goBuildKubernetesSecretDataas priority 1 (before template and default)kubernetes.io/dockerconfigjsonsecret type whenimagePullSecretis configuredpod.Spec.ImagePullSecrets[]referencesDepends on: #256 (Go template support) — this PR builds on the template PR's API and builder signature changes.
🔗 Resolves:
N/A — new feature
✅ Checklist
🕵️ Review Notes &⚠️ Risks
BuildKubernetesSecretData. If configured but fields are missing/invalid, it falls back to the default field mapping with a logged error.imagePullSecretfield is optional. Existing resources behave identically.AreImagePullSecretsUsingSecretsandAppendUpdatedImagePullSecretsso deployments referencing updated imagePullSecrets viapod.Spec.ImagePullSecretsare properly detected for auto-restart./ok-to-test.