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 flexible ImagePullSecrets support #1897

Closed
wants to merge 1 commit into from
Closed

Conversation

pat-s
Copy link
Contributor

@pat-s pat-s commented Jun 29, 2023

Currently ImagePullSecrets is hardcoded to a secret named regcred:

ImagePullSecrets: []v1.LocalObjectReference{{Name: "regcred"}},

This PR aims to make it more flexible and let users specify multiple secrets via a server-wide k8s backend option, similar to labels and annotations.

@woodpecker-ci/maintainers

My golang skils are limited and I've added some FIXMEs in places where I need help for a "proper" implementation.

@pat-s pat-s added agent enhancement improve existing features backend/kubernetes labels Jun 29, 2023
@pat-s pat-s added this to the 1.1.0 milestone Jun 29, 2023
@qwerty287
Copy link
Contributor

Just a general comment: local variables, e.g. as arguments, always should be lowercase.

@qwerty287
Copy link
Contributor

And to get a list instead of a string, use a StringSliceFlag and then StringSlice on the context.

@@ -53,3 +53,9 @@ helm upgrade --install woodpecker-agent --namespace <namespace> woodpecker/woodp
# Uninstall
helm delete woodpecker-agent
```

## ImagePullSecrets
Copy link
Contributor

@zc-devs zc-devs Jul 1, 2023

Choose a reason for hiding this comment

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

Shouldn't it be in docs/docs/30-administration/22-backends/40-kubernetes.md? There also should be description of the env var.

## ImagePullSecrets

By default pods look for a secret named "regcred" in the respective namespace.
Existing secrets can be used by overwriting the default secret name Woodpecker is looking for via the k8s backend option `backend-k8s-pod-image-pull-secret`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Existing secrets can be used by overwriting the default secret name Woodpecker is looking for via the k8s backend option `backend-k8s-pod-image-pull-secret`.
Existing secrets can be used by overwriting the default secret name Woodpecker is looking for via the `WOODPECKER_BACKEND_K8S_IMAGE_PULL_SECRETS` environment variable.

Copy link
Contributor

@qwerty287 qwerty287 left a comment

Choose a reason for hiding this comment

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

You need to adjust the code, but these comments should help you getting it right

Comment on lines +378 to +383
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BACKEND_K8S_IMAGE_PULL_SECRETS"},
Name: "backend-k8s-pod-image-pull-secrets",
Usage: "backend k8s pull secrets for private registries",
Value: "regcred",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BACKEND_K8S_IMAGE_PULL_SECRETS"},
Name: "backend-k8s-pod-image-pull-secrets",
Usage: "backend k8s pull secrets for private registries",
Value: "regcred",
},
&cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_BACKEND_K8S_IMAGE_PULL_SECRETS"},
Name: "backend-k8s-pod-image-pull-secrets",
Usage: "backend k8s pull secrets for private registries",
Value: []string{},
},

Comment on lines +193 to +197
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BACKEND_K8S_IMAGE_PULL_SECRETS"},
Name: "backend-k8s-pod-image-pull-secrets",
Usage: "backend k8s pull secrets for private registries",
Value: "regcred",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BACKEND_K8S_IMAGE_PULL_SECRETS"},
Name: "backend-k8s-pod-image-pull-secrets",
Usage: "backend k8s pull secrets for private registries",
Value: "regcred",
&cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_BACKEND_K8S_IMAGE_PULL_SECRETS"},
Name: "backend-k8s-pod-image-pull-secrets",
Usage: "backend k8s pull secrets for private registries",
Value: []string{},
},

@@ -11,7 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func Pod(namespace string, step *types.Step, labels, annotations map[string]string) (*v1.Pod, error) {
func Pod(namespace string, step *types.Step, labels, annotations map[string]string, ImagePullSecrets) (*v1.Pod, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func Pod(namespace string, step *types.Step, labels, annotations map[string]string, ImagePullSecrets) (*v1.Pod, error) {
func Pod(namespace string, step *types.Step, labels, annotations map[string]string, imagePullSecrets []v1.LocalObjectReference) (*v1.Pod, error) {

@eliasscosta
Copy link
Contributor

Nice PR. Is it possible to assume some default? In general, ServiceAccounts already have this configuration, if we don't set anything they use the configuration inside ServiceAccount.

@qwerty287
Copy link
Contributor

#3016

@6543 6543 deleted the image-pull-secrets-k8s branch December 25, 2023 18:14
@qwerty287 qwerty287 removed this from the 3.x.x milestone Dec 27, 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.

4 participants