Skip to content

Commit

Permalink
fixing observation for legacy key types
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 6, 2023
1 parent 9105ba1 commit 654a646
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion kind/kind.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions operator/iamkeycontroller/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions operator/iamkeycontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down

0 comments on commit 654a646

Please sign in to comment.