forked from aws-controllers-k8s/dynamodb-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GlobalTable resource custom hooks, terminalCodes and e2e tests
Part of aws-controllers-k8s/community#803 Description of changes - Add custom hooks and terminalCodes to `GlobalTable` resource in `generator.yaml` - Add e2e tests for `GlobalTable` create and delete operations By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
Showing
11 changed files
with
410 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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 global_table | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1" | ||
) | ||
|
||
// getSyncedCondition returns the Condition in the resource's Conditions | ||
// collection that is of type ConditionTypeResourceSynced. If no such condition | ||
// is found, returns nil. | ||
func getSyncedCondition(r *resource) *ackv1alpha1.Condition { | ||
return getConditionOfType(r, ackv1alpha1.ConditionTypeResourceSynced) | ||
} | ||
|
||
// getTerminalCondition returns the Condition in the resource's Conditions | ||
// collection that is of type ConditionTypeTerminal. If no such condition is | ||
// found, returns nil. | ||
func getTerminalCondition(r *resource) *ackv1alpha1.Condition { | ||
return getConditionOfType(r, ackv1alpha1.ConditionTypeTerminal) | ||
} | ||
|
||
// getConditionOfType returns the Condition in the resource's Conditions | ||
// collection of the supplied type. If no such condition is found, returns nil. | ||
func getConditionOfType( | ||
r *resource, | ||
condType ackv1alpha1.ConditionType, | ||
) *ackv1alpha1.Condition { | ||
for _, condition := range r.ko.Status.Conditions { | ||
if condition.Type == condType { | ||
return condition | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// setSyncedCondition sets the resource's Condition of type | ||
// ConditionTypeResourceSynced to the supplied status, optional message and | ||
// reason. | ||
func setSyncedCondition( | ||
r *resource, | ||
status corev1.ConditionStatus, | ||
message *string, | ||
reason *string, | ||
) { | ||
c := getSyncedCondition(r) | ||
if c == nil { | ||
c = &ackv1alpha1.Condition{ | ||
Type: ackv1alpha1.ConditionTypeResourceSynced, | ||
} | ||
r.ko.Status.Conditions = append(r.ko.Status.Conditions, c) | ||
} | ||
now := metav1.Now() | ||
c.LastTransitionTime = &now | ||
c.Status = status | ||
} | ||
|
||
// setTerminalCondition sets the resource's Condition of type | ||
// ConditionTypeTerminal to the supplied status, optional message and reason. | ||
// | ||
// TODO(jaypipes): Move to ACK code-gen templates. | ||
func setTerminalCondition( | ||
r *resource, | ||
status corev1.ConditionStatus, | ||
message *string, | ||
reason *string, | ||
) { | ||
c := getSyncedCondition(r) | ||
if c == nil { | ||
c = &ackv1alpha1.Condition{ | ||
Type: ackv1alpha1.ConditionTypeTerminal, | ||
} | ||
r.ko.Status.Conditions = append(r.ko.Status.Conditions, c) | ||
} | ||
now := metav1.Now() | ||
c.LastTransitionTime = &now | ||
c.Status = status | ||
c.Message = message | ||
c.Reason = reason | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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 global_table | ||
|
||
import svcsdk "github.com/aws/aws-sdk-go/service/dynamodb" | ||
|
||
func customSetDeleteInput(r *resource, input *svcsdk.UpdateGlobalTableInput) { | ||
for _, replica := range r.ko.Spec.ReplicationGroup { | ||
replicaUpdate := &svcsdk.ReplicaUpdate{ | ||
Delete: &svcsdk.DeleteReplicaAction{ | ||
RegionName: replica.RegionName, | ||
}, | ||
} | ||
input.ReplicaUpdates = append(input.ReplicaUpdates, replicaUpdate) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// 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 global_table | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1" | ||
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" | ||
) | ||
|
||
var ( | ||
// TerminalStatuses are the status strings that are terminal states for a | ||
// DB instance. | ||
TerminalStatuses = []v1alpha1.GlobalTableStatus_SDK{ | ||
v1alpha1.GlobalTableStatus_SDK_DELETING, | ||
v1alpha1.GlobalTableStatus_SDK_UPDATING, | ||
} | ||
) | ||
|
||
var ( | ||
requeueWaitWhileDeleting = ackrequeue.NeededAfter( | ||
errors.New("GlobalTable in 'DELETING' state, cannot be modified or deleted."), | ||
ackrequeue.DefaultRequeueAfterDuration/6, | ||
) | ||
requeueWaitWhileCreating = ackrequeue.NeededAfter( | ||
errors.New("GlobalTable in 'CREATING' state, cannot be modified or deleted."), | ||
ackrequeue.DefaultRequeueAfterDuration/15, | ||
) | ||
) | ||
|
||
// requeueWaitUntilCanModify returns a `ackrequeue.RequeueNeededAfter` struct | ||
// explaining the DB instance cannot be modified until it reaches an available | ||
// status. | ||
func requeueWaitUntilCanModify(r *resource) *ackrequeue.RequeueNeededAfter { | ||
if r.ko.Status.GlobalTableStatus == nil { | ||
return nil | ||
} | ||
status := *r.ko.Status.GlobalTableStatus | ||
msg := fmt.Sprintf( | ||
"GlobalTable in '%s' state, cannot be modified until '%s'.", | ||
status, v1alpha1.GlobalTableStatus_SDK_ACTIVE, | ||
) | ||
|
||
fmt.Println("REQUE: WAITING UNTIL NEXT", errors.New(msg)) | ||
return ackrequeue.NeededAfter( | ||
errors.New(msg), | ||
ackrequeue.DefaultRequeueAfterDuration/6, | ||
) | ||
} | ||
|
||
// instanceHasTerminalStatus returns whether the supplied DB Instance is in a | ||
// terminal state | ||
func globalTableHasTerminalStatus(r *resource) bool { | ||
if r.ko.Status.GlobalTableStatus == nil { | ||
return false | ||
} | ||
ts := *r.ko.Status.GlobalTableStatus | ||
for _, s := range TerminalStatuses { | ||
if ts == string(s) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// globalTableCreating returns true if the supplied DynamodbDB globalTable is in the process | ||
// of being created | ||
func globalTableCreating(r *resource) bool { | ||
fmt.Println("IS GBCREATING?") | ||
if r.ko.Status.GlobalTableStatus == nil { | ||
fmt.Println("IS GBCREATING? NO") | ||
return false | ||
} | ||
fmt.Println("IS GBCREATING? YES") | ||
dbis := *r.ko.Status.GlobalTableStatus | ||
return dbis == string(v1alpha1.GlobalTableStatus_SDK_CREATING) | ||
} | ||
|
||
// globalTableDeleting returns true if the supplied DynamodbDB globalTable is in the process | ||
// of being deleted | ||
func globalTableDeleting(r *resource) bool { | ||
if r.ko.Status.GlobalTableStatus == nil { | ||
return false | ||
} | ||
dbis := *r.ko.Status.GlobalTableStatus | ||
return dbis == string(v1alpha1.GlobalTableStatus_SDK_DELETING) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: dynamodb.services.k8s.aws/v1alpha1 | ||
kind: GlobalTable | ||
metadata: | ||
name: $GLOBAL_TABLE_NAME | ||
spec: | ||
globalTableName: $GLOBAL_TABLE_NAME | ||
replicationGroup: | ||
- regionName: $REGION_NAME |
Oops, something went wrong.