Skip to content

Commit

Permalink
fix(kafka/cluster): clusterpolicy update + delete
Browse files Browse the repository at this point in the history
Signed-off-by: Charel Baum (external expert on behalf of DB Netz AG) <[email protected]>
(cherry picked from commit 3c3b18c)
  • Loading branch information
Charel Baum (external expert on behalf of DB Netz AG) authored and github-actions[bot] committed Oct 19, 2023
1 parent ab10001 commit 157e33e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions apis/kafka/generator-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ resources:
errors:
404:
code: NotFoundException
fields:
ClusterPolicyVersion:
is_read_only: true
from:
operation: GetClusterPolicy
path: CurrentVersion
2 changes: 2 additions & 0 deletions apis/kafka/v1alpha1/zz_cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apis/kafka/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package/crds/kafka.aws.crossplane.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,9 @@ spec:
clusterARN:
description: The Amazon Resource Name (ARN) of the cluster.
type: string
clusterPolicyVersion:
description: Cluster policy version.
type: string
state:
description: The state of the cluster. The possible states are
ACTIVE, CREATING, DELETING, FAILED, HEALING, MAINTENANCE, REBOOTING_BROKER,
Expand Down
16 changes: 11 additions & 5 deletions pkg/controller/kafka/cluster/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,24 @@ func (u *hooks) getClusterPolicyState(ctx context.Context, wanted *svcapitypes.C
})
if IsNotFound(err) {
if wanted.Spec.ForProvider.ClusterPolicy == nil {
return subResourceOK, "spec.forProvider.clusterPolicy", nil
return subResourceOK, "", nil
}
return subResourceNeedsUpdate, "spec.forProvider.clusterPolicy", nil
}
if err != nil {
return subResourceOK, "", errors.Wrap(err, errGetClusterPolicy)
}

// write clusterPolicy currentVersion into status to be used in potential update and to be visible for user
wanted.Status.AtProvider.ClusterPolicyVersion = res.CurrentVersion

if res.Policy == nil {
if wanted.Spec.ForProvider.ClusterPolicy == nil {
return subResourceNeedsDeletion, "spec.forProvider.clusterPolicy", nil
return subResourceOK, "", nil
}
return subResourceOK, "spec.forProvider.clusterPolicy", nil
return subResourceNeedsUpdate, "spec.forProvider.clusterPolicy", nil
} else if wanted.Spec.ForProvider.ClusterPolicy == nil {
return subResourceNeedsDeletion, "spec.forProvider.clusterPolicy", nil
}

currentPolicy, err := policy.ParsePolicyString(*res.Policy)
Expand Down Expand Up @@ -990,8 +995,9 @@ func (u *hooks) update(ctx context.Context, mg resource.Managed) (managed.Extern
return managed.ExternalUpdate{}, errors.Wrap(err, errMarshalClusterPolicy)
}
_, err = u.client.PutClusterPolicyWithContext(ctx, &svcsdk.PutClusterPolicyInput{
ClusterArn: &currentARN,
Policy: policyRaw,
ClusterArn: &currentARN,
CurrentVersion: cr.Status.AtProvider.ClusterPolicyVersion,
Policy: policyRaw,
})
if err != nil {
return managed.ExternalUpdate{}, errors.Wrap(err, errPutClusterPolicy)
Expand Down

0 comments on commit 157e33e

Please sign in to comment.