-
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
Backup
resource custom hooks, terminalCodes, printcolumns and e2e
tests - Add custom hooks, terminalCodes, printcomns to `generator.yaml` - Regenerate `Backup` resource - Add e2e tests for create and delete operations
- Loading branch information
Showing
9 changed files
with
409 additions
and
2 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,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 backup | ||
|
||
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,83 @@ | ||
// 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 backup | ||
|
||
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.BackupStatus_SDK{} | ||
) | ||
|
||
var ( | ||
requeueWaitWhileDeleting = ackrequeue.NeededAfter( | ||
errors.New("Backup in 'DELETING' state, cannot be modified or deleted."), | ||
ackrequeue.DefaultRequeueAfterDuration/6, | ||
) | ||
requeueWaitWhileCreating = ackrequeue.NeededAfter( | ||
errors.New("Backup 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.BackupStatus == nil { | ||
return nil | ||
} | ||
status := *r.ko.Status.BackupStatus | ||
msg := fmt.Sprintf( | ||
"Backup in '%s' state, cannot be modified until '%s'.", | ||
status, v1alpha1.BackupStatus_SDK_AVAILABLE, | ||
) | ||
|
||
return ackrequeue.NeededAfter( | ||
errors.New(msg), | ||
ackrequeue.DefaultRequeueAfterDuration/6, | ||
) | ||
} | ||
|
||
// instanceHasTerminalStatus returns whether the supplied DB Instance is in a | ||
// terminal state | ||
func backupHasTerminalStatus(r *resource) bool { | ||
if r.ko.Status.BackupStatus == nil { | ||
return false | ||
} | ||
ts := *r.ko.Status.BackupStatus | ||
for _, s := range TerminalStatuses { | ||
if ts == string(s) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// backupCreating returns true if the supplied DynamodbDB backup is in the process | ||
// of being created | ||
func backupCreating(r *resource) bool { | ||
if r.ko.Status.BackupStatus == nil { | ||
return false | ||
} | ||
dbis := *r.ko.Status.BackupStatus | ||
return dbis == string(v1alpha1.BackupStatus_SDK_CREATING) | ||
} |
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,3 @@ | ||
if backupCreating(&resource{ko}) { | ||
return &resource{ko}, requeueWaitWhileCreating | ||
} |
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,7 @@ | ||
apiVersion: dynamodb.services.k8s.aws/v1alpha1 | ||
kind: Backup | ||
metadata: | ||
name: $BACKUP_NAME | ||
spec: | ||
backupName: $BACKUP_NAME | ||
tableName: $TABLE_NAME |
Oops, something went wrong.