mirror of
https://codeberg.org/crowci/crow.git
synced 2025-08-07 20:23:03 +03:00
Implement registries for Kubernetes backend (#4092)
According to [the documentation](https://woodpecker-ci.org/docs/administration/backends/kubernetes#images-from-private-registries), per-organization and per-pipeline registries are currently unsupported for the Kubernetes backend. This patch implements this missing functionality by creating and deleting a matching secret for each pod with a matched registry, using the same name, labels, and annotations as the pod, and appending it to its `imagePullSecrets` list. This patch adds tests for the new functionality, and has been manually end-to-end-tested in KinD by using a private image hosted in the matching gitea instance. This will require updating the matching helm charts to add the create/delete permissions to the agent role, which **is already done**. close #2987
This commit is contained in:
@@ -16,6 +16,7 @@ package kubernetes
|
||||
|
||||
import (
|
||||
"context"
|
||||
std_errs "errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
@@ -225,6 +226,13 @@ func (e *kube) StartStep(ctx context.Context, step *types.Step, taskUUID string)
|
||||
log.Error().Err(err).Msg("could not parse backend options")
|
||||
}
|
||||
|
||||
if needsRegistrySecret(step) {
|
||||
err = startRegistrySecret(ctx, e, step)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("starting step: %s", step.Name)
|
||||
_, err = startPod(ctx, e, step, options)
|
||||
return err
|
||||
@@ -382,9 +390,20 @@ func (e *kube) TailStep(ctx context.Context, step *types.Step, taskUUID string)
|
||||
}
|
||||
|
||||
func (e *kube) DestroyStep(ctx context.Context, step *types.Step, taskUUID string) error {
|
||||
var errs []error
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("Stopping step: %s", step.Name)
|
||||
if needsRegistrySecret(step) {
|
||||
err := stopRegistrySecret(ctx, e, step, defaultDeleteOptions)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
err := stopPod(ctx, e, step, defaultDeleteOptions)
|
||||
return err
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
return std_errs.Join(errs...)
|
||||
}
|
||||
|
||||
// DestroyWorkflow destroys the pipeline environment.
|
||||
|
Reference in New Issue
Block a user