From 654a6468e92eca19f419d1c9dce8f6da911567ac Mon Sep 17 00:00:00 2001 From: "lukasz.widera@vshn.ch" Date: Thu, 6 Jul 2023 10:58:40 +0200 Subject: [PATCH] fixing observation for legacy key types --- Makefile.vars.mk | 6 +++--- kind/kind.mk | 2 +- operator/iamkeycontroller/create.go | 1 + operator/iamkeycontroller/observe.go | 24 ++++++++++++++---------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Makefile.vars.mk b/Makefile.vars.mk index be4a25b3..2f3e53c8 100644 --- a/Makefile.vars.mk +++ b/Makefile.vars.mk @@ -18,7 +18,7 @@ CONTAINER_REGISTRY ?= ghcr.io UPBOUND_CONTAINER_REGISTRY ?= xpkg.upbound.io # Image URL to use all building/pushing image targets -CONTAINER_IMG ?= $(CONTAINER_REGISTRY)/$(PROJECT_OWNER)/$(PROJECT_NAME)/controller:$(IMG_TAG) +CONTAINER_IMG ?= ghcr.io/vshn/provider-exoscale/provider:v0.9.2 LOCAL_PACKAGE_IMG = localhost:5000/$(PROJECT_OWNER)/$(PROJECT_NAME)/package:$(IMG_TAG) GHCR_PACKAGE_IMG ?= $(CONTAINER_REGISTRY)/$(PROJECT_OWNER)/$(PROJECT_NAME)/provider:$(IMG_TAG) UPBOUND_PACKAGE_IMG ?= $(UPBOUND_CONTAINER_REGISTRY)/$(PROJECT_OWNER)/$(PROJECT_NAME):$(IMG_TAG) @@ -28,8 +28,8 @@ UPBOUND_PACKAGE_IMG ?= $(UPBOUND_CONTAINER_REGISTRY)/$(PROJECT_OWNER)/$(PROJECT_ # https://hub.docker.com/r/kindest/node/tags KIND_NODE_VERSION ?= v1.24.0 KIND_IMAGE ?= docker.io/kindest/node:$(KIND_NODE_VERSION) -KIND_KUBECONFIG ?= $(kind_dir)/kind-kubeconfig-$(KIND_NODE_VERSION) -KIND_CLUSTER ?= $(PROJECT_NAME)-$(KIND_NODE_VERSION) +KIND_KUBECONFIG ?= /home/wejdross/vshn/shedar/kindev/.kind/kind-kubeconfig-v1.24.4 +KIND_CLUSTER ?= kindev # TEST:integration ENVTEST_ADDITIONAL_FLAGS ?= --bin-dir "$(kind_dir)" diff --git a/kind/kind.mk b/kind/kind.mk index 91395915..defd91c9 100644 --- a/kind/kind.mk +++ b/kind/kind.mk @@ -26,7 +26,7 @@ kind-setup-ingress: kind-setup ## Install NGINX as ingress controller onto kind # We fix the arch to linux/amd64 since kind runs in amd64 even on Mac/arm. kind-load-image: export GOOS = linux kind-load-image: export GOARCH = amd64 -kind-load-image: kind-setup build-docker ## Load the container image onto kind cluster +kind-load-image: build-docker ## Load the container image onto kind cluster @$(kind_bin) load docker-image --name $(KIND_CLUSTER) $(CONTAINER_IMG) .PHONY: kind-clean diff --git a/operator/iamkeycontroller/create.go b/operator/iamkeycontroller/create.go index 30582b6c..f4096b3b 100644 --- a/operator/iamkeycontroller/create.go +++ b/operator/iamkeycontroller/create.go @@ -161,6 +161,7 @@ func (p *IAMKeyPipeline) createIAMKey(ctx *pipelineContext) error { metav1.SetMetaDataAnnotation(&ctx.iamKey.ObjectMeta, KeyIDAnnotationKey, *ctx.iamExoscaleKey.Key) metav1.SetMetaDataAnnotation(&ctx.iamKey.ObjectMeta, RoleIDAnnotationKey, iamRoleID) + metav1.SetMetaDataAnnotation(&ctx.iamKey.ObjectMeta, "newKeyType", "true") log.Info("IAM Key created", "keyName", ctx.iamKey.Spec.ForProvider.KeyName) defer resp.Body.Close() return nil diff --git a/operator/iamkeycontroller/observe.go b/operator/iamkeycontroller/observe.go index 3f7a3fbe..d5c76359 100644 --- a/operator/iamkeycontroller/observe.go +++ b/operator/iamkeycontroller/observe.go @@ -26,16 +26,20 @@ func (p *IAMKeyPipeline) Observe(ctx context.Context, mg resource.Managed) (mana log.V(1).Info("Observing resource") iamKey := fromManaged(mg) - if iamKey.Status.AtProvider.RoleID == "" { - // get the data generated by Create() via annotations, since in Create() we're not allowed to update the status. - if RoleID, exists := iamKey.Annotations[RoleIDAnnotationKey]; exists { - iamKey.Status.AtProvider.RoleID = RoleID - delete(iamKey.Annotations, RoleIDAnnotationKey) - log.V(1).Info("Deleting annotation", "key", RoleIDAnnotationKey) - } else { - // New resource, create user first - log.V(1).Info("IAM Role not found, returning") - return managed.ExternalObservation{}, nil + // to manage state of new and old keys I need other variable, this is why this annotation is set + // otherwise observation fails for one of key types + if _, exists := iamKey.Annotations["newKeyType"]; exists { + if iamKey.Status.AtProvider.RoleID == "" { + // get the data generated by Create() via annotations, since in Create() we're not allowed to update the status. + if RoleID, exists := iamKey.Annotations[RoleIDAnnotationKey]; exists { + iamKey.Status.AtProvider.RoleID = RoleID + delete(iamKey.Annotations, RoleIDAnnotationKey) + log.V(1).Info("Deleting annotation", "key", RoleIDAnnotationKey) + } else { + // New resource, create user first + log.V(1).Info("IAM Role not found, returning") + return managed.ExternalObservation{}, nil + } } } if iamKey.Status.AtProvider.KeyID == "" {