diff --git a/apis/v1alpha1/ack-generate-metadata.yaml b/apis/v1alpha1/ack-generate-metadata.yaml index 4a76230..31d1749 100755 --- a/apis/v1alpha1/ack-generate-metadata.yaml +++ b/apis/v1alpha1/ack-generate-metadata.yaml @@ -1,14 +1,14 @@ ack_generate_info: - build_date: "2021-09-08T23:45:08Z" - build_hash: 394e8294aabf0b221c35f7a5c7bc7e4e43bc6f10 - go_version: go1.16.4 linux/amd64 + build_date: "2021-09-10T21:06:37Z" + build_hash: a988bddaea3800999e8a548e0e7a4fd44cc00b19 + go_version: go1.14.14 darwin/amd64 version: v0.13.2 -api_directory_checksum: 155104e002d9c69b75fd9e85789bf7ee292b866c +api_directory_checksum: a13caf20935ebb6193efdee1ab377cae33311ad7 api_version: v1alpha1 aws_sdk_go_version: v1.37.10 generator_config_info: - file_checksum: 4bf1e52543400e3d52cc745da4c1e2e518e9e1e1 + file_checksum: 968c7d8481a61c0299fc373cc6d1692a52b55868 original_file_name: generator.yaml last_modification: reason: API generation - timestamp: 2021-09-08 23:45:13.439536495 +0000 UTC + timestamp: 2021-09-10 21:06:47.280077 +0000 UTC diff --git a/apis/v1alpha1/generator.yaml b/apis/v1alpha1/generator.yaml index ae2e7c2..f67fa27 100644 --- a/apis/v1alpha1/generator.yaml +++ b/apis/v1alpha1/generator.yaml @@ -21,10 +21,14 @@ resources: ScalableTarget: is_adoptable: false hooks: - sdk_read_many_post_build_request: - code: rm.customDescribeScalableTarget(ctx, r, input) - delta_pre_compare: - code: customSetDefaults(a, b) + sdk_create_post_set_output: + code: rm.customSetLastModifiedTime(ko) + sdk_read_many_post_build_request: + code: rm.customDescribeScalableTarget(ctx, r, input) + delta_pre_compare: + code: customSetDefaults(a, b) + sdk_update_post_set_output: + code: rm.customSetLastModifiedTime(ko) fields: ResourceID: is_name: true @@ -33,8 +37,18 @@ resources: from: operation: DescribeScalableTargets path: ScalableTargets..CreationTime + LastModifiedTime: + is_read_only: true + from: + operation: DescribeScalableTargets + path: ScalableTargets..CreationTime ScalingPolicy: is_adoptable: false + hooks: + sdk_create_post_set_output: + code: rm.customSetLastModifiedTime(ko) + sdk_update_post_set_output: + code: rm.customSetLastModifiedTime(ko) fields: ResourceID: is_name: true @@ -45,6 +59,11 @@ resources: from: operation: DescribeScalingPolicies path: ScalingPolicies..CreationTime + LastModifiedTime: + is_read_only: true + from: + operation: DescribeScalingPolicies + path: ScalingPolicies..CreationTime ignore: resource_names: - ScheduledAction diff --git a/apis/v1alpha1/scalable_target.go b/apis/v1alpha1/scalable_target.go index 246ba99..6147f9f 100644 --- a/apis/v1alpha1/scalable_target.go +++ b/apis/v1alpha1/scalable_target.go @@ -202,6 +202,9 @@ type ScalableTargetStatus struct { // The Unix timestamp for when the scalable target was created. // +kubebuilder:validation:Optional CreationTime *metav1.Time `json:"creationTime,omitempty"` + // The Unix timestamp for when the scalable target was created. + // +kubebuilder:validation:Optional + LastModifiedTime *metav1.Time `json:"lastModifiedTime,omitempty"` } // ScalableTarget is the Schema for the ScalableTargets API diff --git a/apis/v1alpha1/scaling_policy.go b/apis/v1alpha1/scaling_policy.go index b10fc66..ba61588 100644 --- a/apis/v1alpha1/scaling_policy.go +++ b/apis/v1alpha1/scaling_policy.go @@ -187,6 +187,9 @@ type ScalingPolicyStatus struct { // The Unix timestamp for when the scaling policy was created. // +kubebuilder:validation:Optional CreationTime *metav1.Time `json:"creationTime,omitempty"` + // The Unix timestamp for when the scaling policy was created. + // +kubebuilder:validation:Optional + LastModifiedTime *metav1.Time `json:"lastModifiedTime,omitempty"` } // ScalingPolicy is the Schema for the ScalingPolicies API diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index c6deb29..46ef5e2 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -302,6 +302,10 @@ func (in *ScalableTargetStatus) DeepCopyInto(out *ScalableTargetStatus) { in, out := &in.CreationTime, &out.CreationTime *out = (*in).DeepCopy() } + if in.LastModifiedTime != nil { + in, out := &in.LastModifiedTime, &out.LastModifiedTime + *out = (*in).DeepCopy() + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScalableTargetStatus. @@ -574,6 +578,10 @@ func (in *ScalingPolicyStatus) DeepCopyInto(out *ScalingPolicyStatus) { in, out := &in.CreationTime, &out.CreationTime *out = (*in).DeepCopy() } + if in.LastModifiedTime != nil { + in, out := &in.LastModifiedTime, &out.LastModifiedTime + *out = (*in).DeepCopy() + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScalingPolicyStatus. diff --git a/config/crd/bases/applicationautoscaling.services.k8s.aws_scalabletargets.yaml b/config/crd/bases/applicationautoscaling.services.k8s.aws_scalabletargets.yaml index 9e20a9e..0f7a968 100644 --- a/config/crd/bases/applicationautoscaling.services.k8s.aws_scalabletargets.yaml +++ b/config/crd/bases/applicationautoscaling.services.k8s.aws_scalabletargets.yaml @@ -242,6 +242,10 @@ spec: description: The Unix timestamp for when the scalable target was created. format: date-time type: string + lastModifiedTime: + description: The Unix timestamp for when the scalable target was created. + format: date-time + type: string type: object type: object served: true diff --git a/config/crd/bases/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml b/config/crd/bases/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml index 2cb5f23..d2eac51 100644 --- a/config/crd/bases/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml +++ b/config/crd/bases/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml @@ -333,6 +333,10 @@ spec: description: The Unix timestamp for when the scaling policy was created. format: date-time type: string + lastModifiedTime: + description: The Unix timestamp for when the scaling policy was created. + format: date-time + type: string type: object type: object served: true diff --git a/generator.yaml b/generator.yaml index ae2e7c2..f67fa27 100644 --- a/generator.yaml +++ b/generator.yaml @@ -21,10 +21,14 @@ resources: ScalableTarget: is_adoptable: false hooks: - sdk_read_many_post_build_request: - code: rm.customDescribeScalableTarget(ctx, r, input) - delta_pre_compare: - code: customSetDefaults(a, b) + sdk_create_post_set_output: + code: rm.customSetLastModifiedTime(ko) + sdk_read_many_post_build_request: + code: rm.customDescribeScalableTarget(ctx, r, input) + delta_pre_compare: + code: customSetDefaults(a, b) + sdk_update_post_set_output: + code: rm.customSetLastModifiedTime(ko) fields: ResourceID: is_name: true @@ -33,8 +37,18 @@ resources: from: operation: DescribeScalableTargets path: ScalableTargets..CreationTime + LastModifiedTime: + is_read_only: true + from: + operation: DescribeScalableTargets + path: ScalableTargets..CreationTime ScalingPolicy: is_adoptable: false + hooks: + sdk_create_post_set_output: + code: rm.customSetLastModifiedTime(ko) + sdk_update_post_set_output: + code: rm.customSetLastModifiedTime(ko) fields: ResourceID: is_name: true @@ -45,6 +59,11 @@ resources: from: operation: DescribeScalingPolicies path: ScalingPolicies..CreationTime + LastModifiedTime: + is_read_only: true + from: + operation: DescribeScalingPolicies + path: ScalingPolicies..CreationTime ignore: resource_names: - ScheduledAction diff --git a/helm/crds/applicationautoscaling.services.k8s.aws_scalabletargets.yaml b/helm/crds/applicationautoscaling.services.k8s.aws_scalabletargets.yaml index 9e20a9e..0f7a968 100644 --- a/helm/crds/applicationautoscaling.services.k8s.aws_scalabletargets.yaml +++ b/helm/crds/applicationautoscaling.services.k8s.aws_scalabletargets.yaml @@ -242,6 +242,10 @@ spec: description: The Unix timestamp for when the scalable target was created. format: date-time type: string + lastModifiedTime: + description: The Unix timestamp for when the scalable target was created. + format: date-time + type: string type: object type: object served: true diff --git a/helm/crds/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml b/helm/crds/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml index 2cb5f23..d2eac51 100644 --- a/helm/crds/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml +++ b/helm/crds/applicationautoscaling.services.k8s.aws_scalingpolicies.yaml @@ -333,6 +333,10 @@ spec: description: The Unix timestamp for when the scaling policy was created. format: date-time type: string + lastModifiedTime: + description: The Unix timestamp for when the scaling policy was created. + format: date-time + type: string type: object type: object served: true diff --git a/pkg/resource/scalable_target/custom_api.go b/pkg/resource/scalable_target/custom_api.go index ce9060b..f107e06 100644 --- a/pkg/resource/scalable_target/custom_api.go +++ b/pkg/resource/scalable_target/custom_api.go @@ -15,7 +15,10 @@ package scalable_target import ( "context" + svcapitypes "github.com/aws-controllers-k8s/applicationautoscaling-controller/apis/v1alpha1" svcsdk "github.com/aws/aws-sdk-go/service/applicationautoscaling" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "time" ) func (rm *resourceManager) customDescribeScalableTarget( @@ -31,3 +34,9 @@ func (rm *resourceManager) customDescribeScalableTarget( input.SetResourceIds(resourceIDList) } } + +// customSetOutputUpdate sets the LastModifiedTime field to the current time post an update +func (rm *resourceManager) customSetLastModifiedTime(ko *svcapitypes.ScalableTarget) { + currentTime := metav1.Time{Time: time.Now().UTC()} + ko.Status.LastModifiedTime = ¤tTime +} diff --git a/pkg/resource/scalable_target/sdk.go b/pkg/resource/scalable_target/sdk.go index 310771d..5dfb8b4 100644 --- a/pkg/resource/scalable_target/sdk.go +++ b/pkg/resource/scalable_target/sdk.go @@ -192,6 +192,7 @@ func (rm *resourceManager) sdkCreate( ko := desired.ko.DeepCopy() rm.setStatusDefaults(ko) + rm.customSetLastModifiedTime(ko) return &resource{ko}, nil } @@ -266,6 +267,7 @@ func (rm *resourceManager) sdkUpdate( ko := desired.ko.DeepCopy() rm.setStatusDefaults(ko) + rm.customSetLastModifiedTime(ko) return &resource{ko}, nil } diff --git a/pkg/resource/scaling_policy/custom_api.go b/pkg/resource/scaling_policy/custom_api.go new file mode 100644 index 0000000..c474e09 --- /dev/null +++ b/pkg/resource/scaling_policy/custom_api.go @@ -0,0 +1,26 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package scaling_policy + +import ( + svcapitypes "github.com/aws-controllers-k8s/applicationautoscaling-controller/apis/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "time" +) + +// customSetOutputUpdate sets the LastModifiedTime field to the current time post an update +func (rm *resourceManager) customSetLastModifiedTime(ko *svcapitypes.ScalingPolicy) { + currentTime := metav1.Time{Time: time.Now().UTC()} + ko.Status.LastModifiedTime = ¤tTime +} diff --git a/pkg/resource/scaling_policy/sdk.go b/pkg/resource/scaling_policy/sdk.go index 9290dba..f14f6c5 100644 --- a/pkg/resource/scaling_policy/sdk.go +++ b/pkg/resource/scaling_policy/sdk.go @@ -314,6 +314,7 @@ func (rm *resourceManager) sdkCreate( } rm.setStatusDefaults(ko) + rm.customSetLastModifiedTime(ko) return &resource{ko}, nil } @@ -485,6 +486,7 @@ func (rm *resourceManager) sdkUpdate( } rm.setStatusDefaults(ko) + rm.customSetLastModifiedTime(ko) return &resource{ko}, nil }