-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Table
resource custom hooks, terminalCodes, printcolumns and e2…
…e tests - Add custom hooks, terminalCodes, printcomns to `generator.yaml` - Regenerate `Table` resource - Add e2e tests for create and delete operations
- Loading branch information
Showing
19 changed files
with
662 additions
and
3 deletions.
There are no files selected for viewing
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
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
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,93 @@ | ||
// 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 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. | ||
// | ||
// TODO(jaypipes): Move to ACK code-gen templates. | ||
func getSyncedCondition(r *resource) *ackv1alpha1.Condition { | ||
return getConditionOfType(r, ackv1alpha1.ConditionTypeResourceSynced) | ||
} | ||
|
||
// getConditionOfType returns the Condition in the resource's Conditions | ||
// collection of the supplied type. If no such condition is found, returns nil. | ||
// | ||
// TODO(jaypipes): Move to ACK code-gen templates. | ||
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. | ||
// | ||
// TODO(jaypipes): Move to ACK code-gen templates. | ||
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,97 @@ | ||
// 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 table | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1" | ||
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue" | ||
) | ||
|
||
var ( | ||
ErrTableDeleting = errors.New("table in 'DELETING' state, cannot be modified or deleted") | ||
ErrTableCreating = errors.New("table in 'CREATING' state, cannot be modified or deleted") | ||
ErrTableUpdating = errors.New("table in 'UPDATING' state, cannot be modified or deleted") | ||
) | ||
|
||
var ( | ||
// TerminalStatuses are the status strings that are terminal states for a | ||
// DynamoDB table | ||
TerminalStatuses = []v1alpha1.TableStatus_SDK{ | ||
v1alpha1.TableStatus_SDK_ARCHIVING, | ||
v1alpha1.TableStatus_SDK_DELETING, | ||
} | ||
) | ||
|
||
var ( | ||
requeueWaitWhileDeleting = ackrequeue.NeededAfter( | ||
ErrTableDeleting, | ||
5*time.Second, | ||
) | ||
requeueWaitWhileCreating = ackrequeue.NeededAfter( | ||
ErrTableDeleting, | ||
5*time.Second, | ||
) | ||
requeueWaitWhileUpdating = ackrequeue.NeededAfter( | ||
ErrTableUpdating, | ||
5*time.Second, | ||
) | ||
) | ||
|
||
// tableHasTerminalStatus returns whether the supplied Dynamodb table is in a | ||
// terminal state | ||
func tableHasTerminalStatus(r *resource) bool { | ||
if r.ko.Status.TableStatus == nil { | ||
return false | ||
} | ||
ts := *r.ko.Status.TableStatus | ||
for _, s := range TerminalStatuses { | ||
if ts == string(s) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// tableCreating returns true if the supplied DynamodbDB table is in the process | ||
// of being created | ||
func tableCreating(r *resource) bool { | ||
if r.ko.Status.TableStatus == nil { | ||
return false | ||
} | ||
dbis := *r.ko.Status.TableStatus | ||
return dbis == string(v1alpha1.TableStatus_SDK_CREATING) | ||
} | ||
|
||
// tableDeleting returns true if the supplied DynamodbDB table is in the process | ||
// of being deleted | ||
func tableDeleting(r *resource) bool { | ||
if r.ko.Status.TableStatus == nil { | ||
return false | ||
} | ||
dbis := *r.ko.Status.TableStatus | ||
return dbis == string(v1alpha1.TableStatus_SDK_DELETING) | ||
} | ||
|
||
// tableUpdating returns true if the supplied DynamodbDB table is in the process | ||
// of being deleted | ||
func tableUpdating(r *resource) bool { | ||
if r.ko.Status.TableStatus == nil { | ||
return false | ||
} | ||
dbis := *r.ko.Status.TableStatus | ||
return dbis == string(v1alpha1.TableStatus_SDK_UPDATING) | ||
} |
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,6 @@ | ||
if tableDeleting(r) { | ||
return requeueWaitWhileDeleting | ||
} | ||
if tableUpdating(r) { | ||
return requeueWaitWhileUpdating | ||
} |
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,6 @@ | ||
if tableCreating(&resource{ko}) { | ||
return &resource{ko}, requeueWaitWhileCreating | ||
} | ||
if tableUpdating(&resource{ko}) { | ||
return &resource{ko}, requeueWaitWhileUpdating | ||
} |
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,21 @@ | ||
if tableDeleting(latest) { | ||
msg := "table is currently being deleted" | ||
setSyncedCondition(desired, corev1.ConditionFalse, &msg, nil) | ||
return desired, requeueWaitWhileDeleting | ||
} | ||
if tableCreating(latest) { | ||
msg := "table is currently being created" | ||
setSyncedCondition(desired, corev1.ConditionFalse, &msg, nil) | ||
return desired, requeueWaitWhileCreating | ||
} | ||
if tableUpdating(latest) { | ||
msg := "table is currently being created" | ||
setSyncedCondition(desired, corev1.ConditionFalse, &msg, nil) | ||
return desired, requeueWaitWhileUpdating | ||
} | ||
if tableHasTerminalStatus(latest) { | ||
msg := "table is in '"+*latest.ko.Status.TableStatus+"' status" | ||
setTerminalCondition(desired, corev1.ConditionTrue, &msg, nil) | ||
setSyncedCondition(desired, corev1.ConditionTrue, nil, nil) | ||
return desired, nil | ||
} |
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,3 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
**/bootstrap.yaml |
Oops, something went wrong.