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

feat: support for harbor retention policies #267

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/remote-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ jobs:

- name: Configure node IP in kind-config.yaml
run: |
docker network create remote-controller
LAGOON_KIND_CIDR_BLOCK=$(docker network inspect remote-controller | jq '. [0].IPAM.Config[0].Subnet' | tr -d '"')
docker network create kind
LAGOON_KIND_CIDR_BLOCK=$(docker network inspect kind | jq '. [0].IPAM.Config[0].Subnet' | tr -d '"')
export KIND_NODE_IP=$(echo ${LAGOON_KIND_CIDR_BLOCK%???} | awk -F'.' '{print $1,$2,$3,240}' OFS='.')
envsubst < test-resources/test-suite.kind-config.yaml.tpl > test-resources/test-suite.kind-config.yaml

Expand All @@ -110,7 +110,7 @@ jobs:

- name: Check node IP matches kind configuration
run: |
LAGOON_KIND_CIDR_BLOCK=$(docker network inspect remote-controller | jq '. [0].IPAM.Config[0].Subnet' | tr -d '"')
LAGOON_KIND_CIDR_BLOCK=$(docker network inspect kind | jq '. [0].IPAM.Config[0].Subnet' | tr -d '"')
NODE_IP=$(echo ${LAGOON_KIND_CIDR_BLOCK%???} | awk -F'.' '{print $1,$2,$3,240}' OFS='.')
echo Checking for NODE_IP "$NODE_IP"
grep $NODE_IP test-resources/test-suite.kind-config.yaml
Expand All @@ -127,4 +127,4 @@ jobs:

- name: Run github/test-e2e
run: |
make github/test-e2e HARBOR_VERSION=${{matrix.harbor}} OVERRIDE_BUILD_DEPLOY_DIND_IMAGE="${{matrix.lagoon_build_image}}"
make github/test-e2e HARBOR_VERSION=${{matrix.harbor}} OVERRIDE_BUILD_DEPLOY_DIND_IMAGE="${{matrix.lagoon_build_image}}" KIND_NETWORK=kind
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ bin
*~

test-resources/test-suite.kind-config.yaml
test-resources/test-suite.metallb-pool.yaml
test-resources/test-suite.metallb-pool.yaml

local-dev
38 changes: 30 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,33 @@ INGRESS_VERSION=4.9.1
HARBOR_VERSION=1.14.3

KIND_CLUSTER ?= remote-controller
KIND_NETWORK ?= remote-controller

TIMEOUT = 30m
HELM = helm
KUBECTL = kubectl
JQ = jq

ARCH := $(shell uname | tr '[:upper:]' '[:lower:]')

KIND = $(realpath ./local-dev/kind)
KIND_VERSION = v0.25.0

.PHONY: local-dev/kind
local-dev/kind:
ifeq ($(KIND_VERSION), $(shell kind version 2>/dev/null | sed -nE 's/kind (v[0-9.]+).*/\1/p'))
$(info linking local kind version $(KIND_VERSION))
ln -sf $(shell command -v kind) ./local-dev/kind
else
ifneq ($(KIND_VERSION), $(shell ./local-dev/kind version 2>/dev/null | sed -nE 's/kind (v[0-9.]+).*/\1/p'))
$(info downloading kind version $(KIND_VERSION) for $(ARCH))
mkdir -p local-dev
rm local-dev/kind || true
curl -sSLo local-dev/kind https://kind.sigs.k8s.io/dl/$(KIND_VERSION)/kind-$(ARCH)-amd64
chmod a+x local-dev/kind
endif
endif

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down Expand Up @@ -140,7 +161,7 @@ endif

.PHONY: install-metallb
install-metallb:
LAGOON_KIND_CIDR_BLOCK=$$(docker network inspect $(KIND_CLUSTER) | $(JQ) '. [0].IPAM.Config[0].Subnet' | tr -d '"') && \
LAGOON_KIND_CIDR_BLOCK=$$(docker network inspect $(KIND_NETWORK) | $(JQ) '. [0].IPAM.Config[0].Subnet' | tr -d '"') && \
export LAGOON_KIND_NETWORK_RANGE=$$(echo $${LAGOON_KIND_CIDR_BLOCK%???} | awk -F'.' '{print $$1,$$2,$$3,240}' OFS='.')/29 && \
$(HELM) upgrade \
--install \
Expand All @@ -152,7 +173,7 @@ install-metallb:
metallb \
metallb/metallb && \
$$(envsubst < test-resources/test-suite.metallb-pool.yaml.tpl > test-resources/test-suite.metallb-pool.yaml) && \
$(KUBECTL) apply -f test-resources/test-suite.metallb-pool.yaml \
$(KUBECTL) apply -f test-resources/test-suite.metallb-pool.yaml

# cert-manager is used to allow self-signed certificates to be generated automatically by ingress in the same way lets-encrypt would
.PHONY: install-certmanager
Expand Down Expand Up @@ -246,11 +267,12 @@ install-lagoon-remote: install-registry

.PHONY: create-kind-cluster
create-kind-cluster:
docker network inspect $(KIND_CLUSTER) >/dev/null || docker network create $(KIND_CLUSTER) \
&& LAGOON_KIND_CIDR_BLOCK=$$(docker network inspect $(KIND_CLUSTER) | $(JQ) '. [0].IPAM.Config[0].Subnet' | tr -d '"') \
docker network inspect $(KIND_NETWORK) >/dev/null || docker network create $(KIND_NETWORK) \
&& LAGOON_KIND_CIDR_BLOCK=$$(docker network inspect $(KIND_NETWORK) | $(JQ) '. [0].IPAM.Config[0].Subnet' | tr -d '"') \
&& export KIND_NODE_IP=$$(echo $${LAGOON_KIND_CIDR_BLOCK%???} | awk -F'.' '{print $$1,$$2,$$3,240}' OFS='.') \
&& envsubst < test-resources/test-suite.kind-config.yaml.tpl > test-resources/test-suite.kind-config.yaml \
&& kind create cluster --wait=60s --name=$(KIND_CLUSTER) --config=test-resources/test-suite.kind-config.yaml
&& export KIND_EXPERIMENTAL_DOCKER_NETWORK=$(KIND_NETWORK) \
&& $(KIND) create cluster --wait=60s --name=$(KIND_CLUSTER) --config=test-resources/test-suite.kind-config.yaml

# Create a kind cluster locally and run the test e2e test suite against it
.PHONY: kind/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up locally
Expand All @@ -259,22 +281,22 @@ kind/test-e2e: create-kind-cluster install-lagoon-remote kind/re-test-e2e
.PHONY: local-kind/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up locally
kind/re-test-e2e:
export KIND_CLUSTER=$(KIND_CLUSTER) && \
kind export kubeconfig --name=$(KIND_CLUSTER) && \
$(KIND) export kubeconfig --name=$(KIND_CLUSTER) && \
export HARBOR_VERSION=$(HARBOR_VERSION) && \
export OVERRIDE_BUILD_DEPLOY_DIND_IMAGE=$(OVERRIDE_BUILD_DEPLOY_DIND_IMAGE) && \
$(MAKE) test-e2e

.PHONY: clean
kind/clean:
docker compose down && \
kind delete cluster --name=$(KIND_CLUSTER) && docker network rm $(KIND_CLUSTER)
$(KIND) delete cluster --name=$(KIND_CLUSTER) && docker network rm $(KIND_NETWORK)

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up inside github action.
test-e2e:
export HARBOR_VERSION=$(HARBOR_VERSION) && \
export OVERRIDE_BUILD_DEPLOY_DIND_IMAGE=$(OVERRIDE_BUILD_DEPLOY_DIND_IMAGE) && \
go test ./test/e2e/ -v -ginkgo.v
go test ./test/e2e/ -v -ginkgo.v -timeout 20m

.PHONY: github/test-e2e
github/test-e2e: install-lagoon-remote test-e2e
Expand Down
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ func main() {
enableDebug,
lffSupportK8UPv2,
cache,
harborConfig,
)

c := cron.New()
Expand Down
1 change: 1 addition & 0 deletions config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ spec:
- "--enable-deprecated-apis"
- "--lagoon-feature-flag-support-k8upv2"
- "--skip-tls-verify"
- "--cleanup-harbor-repository-on-delete" # enabled for tests
ports:
- containerPort: 8443
name: https
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect
github.com/cxmcc/unixsums v0.0.0-20131125091133-89564297d82f // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cxmcc/unixsums v0.0.0-20131125091133-89564297d82f h1:PkAFGgVtJnasAxOaiEY1RYPx8W+7X7l66vi8T2apKCM=
github.com/cxmcc/unixsums v0.0.0-20131125091133-89564297d82f/go.mod h1:XJq7OckzkOtlgeEKFwkH2gFbc1+1WRFUBf7QnvfyrzQ=
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/d2g/dhcp4 v0.0.0-20170904100407-a1d1b6c41b1c/go.mod h1:Ct2BUK8SB0YC1SMSibvLzxjeJLnrYEVLULFNiHY9YfQ=
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/v1beta1/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (r *LagoonBuildReconciler) createNamespaceBuild(ctx context.Context,
continue
}
// send the status change to lagoon
r.updateDeploymentAndEnvironmentTask(ctx, opLog, runningBuild, nil, buildCondition, "cancelled")
r.updateDeploymentAndEnvironmentTask(opLog, runningBuild, nil, buildCondition, "cancelled")
continue
}
// handle processing running but no pod/failed pod builds
Expand Down
12 changes: 6 additions & 6 deletions internal/controllers/v1beta1/build_deletionhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ Build cancelled
}
// send any messages to lagoon message queues
// update the deployment with the status of cancelled in lagoon
r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
r.buildLogsToLagoonLogs(ctx, opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusCancelled)
r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusCancelled)
}
return nil
}

// buildLogsToLagoonLogs sends the build logs to the lagoon-logs message queue
// it contains the actual pod log output that is sent to elasticsearch, it is what eventually is displayed in the UI
func (r *LagoonBuildReconciler) buildLogsToLagoonLogs(ctx context.Context,
func (r *LagoonBuildReconciler) buildLogsToLagoonLogs(
opLog logr.Logger,
lagoonBuild *lagoonv1beta1.LagoonBuild,
logs []byte,
Expand Down Expand Up @@ -267,7 +267,7 @@ func (r *LagoonBuildReconciler) buildLogsToLagoonLogs(ctx context.Context,

// updateDeploymentAndEnvironmentTask sends the status of the build and deployment to the controllerhandler message queue in lagoon,
// this is for the handler in lagoon to process.
func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask(ctx context.Context,
func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask(
opLog logr.Logger,
lagoonBuild *lagoonv1beta1.LagoonBuild,
lagoonEnv *corev1.ConfigMap,
Expand Down Expand Up @@ -361,7 +361,7 @@ func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask(ctx context.C
}

// buildStatusLogsToLagoonLogs sends the logs to lagoon-logs message queue, used for general messaging
func (r *LagoonBuildReconciler) buildStatusLogsToLagoonLogs(ctx context.Context,
func (r *LagoonBuildReconciler) buildStatusLogsToLagoonLogs(
opLog logr.Logger,
lagoonBuild *lagoonv1beta1.LagoonBuild,
lagoonEnv *corev1.ConfigMap,
Expand Down
23 changes: 12 additions & 11 deletions internal/controllers/v1beta1/build_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (r *LagoonBuildReconciler) getOrCreateNamespace(ctx context.Context, namesp
return fmt.Errorf("error getting harbor version, check your harbor configuration. Error was: %v", err)
}
if lagoonHarbor.UseV2Functions(curVer) {
hProject, err := lagoonHarbor.CreateProjectV2(ctx, lagoonBuild.Spec.Project.Name)
hProject, err := lagoonHarbor.CreateProjectV2(ctx, *namespace)
if err != nil {
return fmt.Errorf("error creating harbor project: %v", err)
}
Expand Down Expand Up @@ -330,8 +330,9 @@ func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Log
}

var serviceaccountTokenSecret string
reg, _ := regexp.Compile("^lagoon-deployer-token")
for _, secret := range serviceAccount.Secrets {
match, _ := regexp.MatchString("^lagoon-deployer-token", secret.Name)
match := reg.MatchString(secret.Name)
if match {
serviceaccountTokenSecret = secret.Name
break
Expand Down Expand Up @@ -896,13 +897,13 @@ func (r *LagoonBuildReconciler) updateQueuedBuild(
// send any messages to lagoon message queues
// update the deployment with the status, lagoon v2.12.0 supports queued status, otherwise use pending
if lagoonv1beta1.CheckLagoonVersion(&lagoonBuild, "2.12.0") {
r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.buildLogsToLagoonLogs(ctx, opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusQueued)
r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusQueued)
} else {
r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.buildLogsToLagoonLogs(ctx, opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusPending)
r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength))
r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusPending)

}
return nil
Expand Down Expand Up @@ -955,10 +956,10 @@ Build cancelled
}
// send any messages to lagoon message queues
// update the deployment with the status of cancelled in lagoon
r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagoonv1beta1.BuildStatusCancelled, "cancelled")
if cancelled {
r.buildLogsToLagoonLogs(ctx, opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusCancelled)
r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagoonv1beta1.BuildStatusCancelled)
}
// delete the build from the lagoon namespace in kubernetes entirely
err = r.Delete(ctx, &lagoonBuild)
Expand Down
57 changes: 29 additions & 28 deletions internal/controllers/v1beta1/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (r *LagoonTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// The object is being deleted
if helpers.ContainsString(lagoonTask.ObjectMeta.Finalizers, taskFinalizer) {
// our finalizer is present, so lets handle any external dependency
if err := r.deleteExternalResources(ctx, &lagoonTask, req.NamespacedName.Namespace); err != nil {
if err := r.deleteExternalResources(); err != nil {
// if fail to delete the external dependency here, return with error
// so that it can be retried
return ctrl.Result{}, err
Expand Down Expand Up @@ -130,7 +130,7 @@ func (r *LagoonTaskReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

func (r *LagoonTaskReconciler) deleteExternalResources(ctx context.Context, lagoonTask *lagoonv1beta1.LagoonTask, namespace string) error {
func (r *LagoonTaskReconciler) deleteExternalResources() error {
// delete any external resources if required
return nil
}
Expand Down Expand Up @@ -266,34 +266,34 @@ func (r *LagoonTaskReconciler) getTaskPodDeployment(ctx context.Context, lagoonT
lagoonTask.Spec.Task.Command,
}
dep.Spec.Template.Spec.RestartPolicy = "Never"
taskPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: lagoonTask.ObjectMeta.Name,
Namespace: lagoonTask.ObjectMeta.Namespace,
Labels: map[string]string{
"lagoon.sh/jobType": "task",
"lagoon.sh/taskName": lagoonTask.ObjectMeta.Name,
"lagoon.sh/crdVersion": crdVersion,
"lagoon.sh/controller": r.ControllerNamespace,
},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: fmt.Sprintf("%v", lagoonv1beta1.GroupVersion),
Kind: "LagoonTask",
Name: lagoonTask.ObjectMeta.Name,
UID: lagoonTask.UID,
},
}
taskPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: lagoonTask.ObjectMeta.Name,
Namespace: lagoonTask.ObjectMeta.Namespace,
Labels: map[string]string{
"lagoon.sh/jobType": "task",
"lagoon.sh/taskName": lagoonTask.ObjectMeta.Name,
"lagoon.sh/crdVersion": crdVersion,
"lagoon.sh/controller": r.ControllerNamespace,
},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: fmt.Sprintf("%v", lagoonv1beta1.GroupVersion),
Kind: "LagoonTask",
Name: lagoonTask.ObjectMeta.Name,
UID: lagoonTask.UID,
},
},
Spec: dep.Spec.Template.Spec,
}
// set the organization labels on task pods
if lagoonTask.Spec.Project.Organization != nil {
taskPod.ObjectMeta.Labels["organization.lagoon.sh/id"] = fmt.Sprintf("%d", *lagoonTask.Spec.Project.Organization.ID)
taskPod.ObjectMeta.Labels["organization.lagoon.sh/name"] = lagoonTask.Spec.Project.Organization.Name
}
return taskPod, nil
},
Spec: dep.Spec.Template.Spec,
}
// set the organization labels on task pods
if lagoonTask.Spec.Project.Organization != nil {
taskPod.ObjectMeta.Labels["organization.lagoon.sh/id"] = fmt.Sprintf("%d", *lagoonTask.Spec.Project.Organization.ID)
taskPod.ObjectMeta.Labels["organization.lagoon.sh/name"] = lagoonTask.Spec.Project.Organization.Name
}
return taskPod, nil
}
}
if !hasService {
Expand Down Expand Up @@ -425,8 +425,9 @@ func (r *LagoonTaskReconciler) createAdvancedTask(ctx context.Context, lagoonTas
return err
}
var serviceaccountTokenSecret string
reg, _ := regexp.Compile("^lagoon-deployer-token")
for _, secret := range serviceAccount.Secrets {
match, _ := regexp.MatchString("^lagoon-deployer-token", secret.Name)
match := reg.MatchString(secret.Name)
if match {
serviceaccountTokenSecret = secret.Name
break
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/v1beta2/build_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (r *LagoonBuildReconciler) getOrCreateNamespace(ctx context.Context, namesp
return fmt.Errorf("error getting harbor version, check your harbor configuration. Error was: %v", err)
}
if lagoonHarbor.UseV2Functions(curVer) {
hProject, err := lagoonHarbor.CreateProjectV2(ctx, lagoonBuild.Spec.Project.Name)
hProject, err := lagoonHarbor.CreateProjectV2(ctx, *namespace)
if err != nil {
return fmt.Errorf("error creating harbor project: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/v1beta2/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (r *LagoonTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// The object is being deleted
if helpers.ContainsString(lagoonTask.ObjectMeta.Finalizers, taskFinalizer) {
// our finalizer is present, so lets handle any external dependency
if err := r.deleteExternalResources(ctx, &lagoonTask, req.NamespacedName.Namespace); err != nil {
if err := r.deleteExternalResources(ctx, &lagoonTask, ""); err != nil {
// if fail to delete the external dependency here, return with error
// so that it can be retried
return ctrl.Result{}, err
Expand Down
2 changes: 1 addition & 1 deletion internal/harbor/harbor_credentialrotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (h *Harbor) RotateRobotCredential(ctx context.Context, cl client.Client, ns
return false, fmt.Errorf("error checking harbor version: %v", err)
}
if h.UseV2Functions(curVer) {
hProject, err := h.CreateProjectV2(ctx, ns.Labels["lagoon.sh/project"])
hProject, err := h.CreateProjectV2(ctx, ns)
if err != nil {
return false, fmt.Errorf("error getting or creating project: %v", err)
}
Expand Down
Loading
Loading