Skip to content

Commit

Permalink
ignore policyName and use metadata name
Browse files Browse the repository at this point in the history
  • Loading branch information
stefnans committed Aug 9, 2024
1 parent 4b6c912 commit 6ca4224
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 45 deletions.
2 changes: 2 additions & 0 deletions apis/cloudwatchlogs/generator-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ignore:
- ExportTask
field_paths:
- CreateLogGroupInput.KmsKeyId
- PutResourcePolicyInput.PolicyName
- DeleteResourcePolicyInput.PolicyName
operations:
PutResourcePolicy:
operation_type:
Expand Down
10 changes: 5 additions & 5 deletions apis/cloudwatchlogs/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 3 additions & 3 deletions apis/cloudwatchlogs/v1alpha1/zz_resource_policy.go

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

3 changes: 1 addition & 2 deletions examples/cloudwatchlogs/resourcepolicy.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
apiVersion: cloudwatchlogs.aws.crossplane.io/v1alpha1
kind: ResourcePolicy
metadata:
name: sample-resource-policy
name: my-example-resource-policy
spec:
forProvider:
region: eu-central-1
policyName: my-example-resource-policy
policyDocument: |
{
"Version": "2012-10-17",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ spec:
{ "aws:SourceArn": "myRoute53ResourceArn" }, "StringEquals": { "aws:SourceAccount":
"myAwsAccountId" } } } ] }
type: string
policyName:
description: Name of the new policy. This parameter is required.
type: string
region:
description: Region is which region the ResourcePolicy will be
created.
Expand Down Expand Up @@ -293,6 +290,9 @@ spec:
of milliseconds after Jan 1, 1970 00:00:00 UTC.
format: int64
type: integer
policyName:
description: The name of the resource policy.
type: string
type: object
conditions:
description: Conditions of the resource.
Expand Down
37 changes: 16 additions & 21 deletions pkg/controller/cloudwatchlogs/resourcepolicy/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/crossplane-contrib/provider-aws/apis/v1alpha1"
"github.com/crossplane-contrib/provider-aws/pkg/clients/iam"
"github.com/crossplane-contrib/provider-aws/pkg/features"
"github.com/crossplane-contrib/provider-aws/pkg/utils/pointer"
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/event"
Expand All @@ -32,10 +33,9 @@ func SetupResourcePolicy(mgr ctrl.Manager, o controller.Options) error {

opts := []option{
func(e *external) {
// e.preObserve = preObserve
// e.preCreate = preCreate
// e.preUpdate = preUpdate
// e.preDelete = preDelete
e.preCreate = preCreate
e.preUpdate = preUpdate
e.preDelete = preDelete
e.postObserve = postObserve
e.isUpToDate = isUpToDate
},
Expand All @@ -55,25 +55,20 @@ func SetupResourcePolicy(mgr ctrl.Manager, o controller.Options) error {
managed.WithConnectionPublishers(cps...)))
}

// func preObserve(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.DescribeResourcePoliciesInput) error {
// obj.PolicyName = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
// return nil
// }

// func preCreate(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.PutResourcePolicyInput) error {
// obj.PolicyName = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
// return nil
// }
func preCreate(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.PutResourcePolicyInput) error {
obj.PolicyName = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
return nil
}

// func preUpdate(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.PutResourcePolicyInput) error {
// obj.PolicyName = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
// return nil
// }
func preUpdate(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.PutResourcePolicyInput) error {
obj.PolicyName = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
return nil
}

// func preDelete(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.DeleteResourcePolicyInput) (bool, error) {
// obj.PolicyName = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
// return true, nil
// }
func preDelete(_ context.Context, cr *svcapitypes.ResourcePolicy, obj *svcsdk.DeleteResourcePolicyInput) (bool, error) {
obj.PolicyName = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
return true, nil
}

func postObserve(_ context.Context, cr *svcapitypes.ResourcePolicy, _ *svcsdk.DescribeResourcePoliciesOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) {
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/cloudwatchlogs/resourcepolicy/zz_controller.go

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

11 changes: 2 additions & 9 deletions pkg/controller/cloudwatchlogs/resourcepolicy/zz_conversions.go

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

0 comments on commit 6ca4224

Please sign in to comment.