generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 277
NTHv2 core functionality #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ac0ce04
core functionality
cjerad 68b973e
fix capitalization
cjerad 2beddc7
add more ways to specify AWS region
cjerad c4ee5fb
tidy up interface organization
cjerad 0407de6
remove SQS request params from Terminator spec
cjerad 69a0544
update copyright attribution
cjerad 17c2ad0
remove boilerplate comment
cjerad d217816
expand "Addr" to "Address"
cjerad 87dccd7
fix capitalization
cjerad 6a7b44b
rename event files
cjerad ab10afa
add more logging for parsing failures
cjerad 186caec
dedup lifecycle action completion code
cjerad ef556fc
add more test cases
cjerad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
core functionality
* Add SQS parameters to Terminator spec * Add drain parameters to Terminator spec * Fetch messages from SQS queue * Cordon and drain nodes targeted in SQS messages
- Loading branch information
commit ac0ce04e258c6c96d2546e976129eb47dd00845b
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| /* | ||
| Copyright 2022. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License 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 v1alpha1 | ||
|
|
||
| import ( | ||
| "go.uber.org/zap/zapcore" | ||
| ) | ||
|
|
||
| func (t *TerminatorSpec) MarshalLogObject(enc zapcore.ObjectEncoder) error { | ||
| enc.AddObject("sqs", t.Sqs) | ||
| enc.AddObject("drain", t.Drain) | ||
| return nil | ||
| } | ||
|
|
||
| func (s SqsSpec) MarshalLogObject(enc zapcore.ObjectEncoder) error { | ||
| enc.AddArray("attributeNames", zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error { | ||
| for _, attrName := range s.AttributeNames { | ||
| enc.AppendString(attrName) | ||
| } | ||
| return nil | ||
| })) | ||
|
|
||
| enc.AddInt64("maxNumberOfMessages", s.MaxNumberOfMessages) | ||
|
|
||
| enc.AddArray("messageAttributeNames", zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error { | ||
| for _, attrName := range s.MessageAttributeNames { | ||
| enc.AppendString(attrName) | ||
| } | ||
| return nil | ||
| })) | ||
|
|
||
| enc.AddString("queueUrl", s.QueueUrl) | ||
| enc.AddInt64("visibilityTimeoutSeconds", s.VisibilityTimeoutSeconds) | ||
| enc.AddInt64("waitTimeSeconds", s.WaitTimeSeconds) | ||
| return nil | ||
| } | ||
|
|
||
| func (d DrainSpec) MarshalLogObject(enc zapcore.ObjectEncoder) error { | ||
| enc.AddBool("force", d.Force) | ||
| enc.AddInt("gracePeriodSeconds", d.GracePeriodSeconds) | ||
| enc.AddBool("ignoreAllDaemonSets", d.IgnoreAllDaemonSets) | ||
| enc.AddBool("deleteEmptyDirData", d.DeleteEmptyDirData) | ||
| enc.AddInt("timeoutSeconds", d.TimeoutSeconds) | ||
| return nil | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ import ( | |
| "context" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "knative.dev/pkg/apis" | ||
| ) | ||
|
|
||
| // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! | ||
|
|
@@ -31,8 +30,29 @@ type TerminatorSpec struct { | |
| // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
| // Important: Run "make" to regenerate code after modifying this file | ||
|
|
||
| // Foo is an example field of Terminator. Edit terminator_types.go to remove/update | ||
| Foo string `json:"foo,omitempty"` | ||
| Sqs SqsSpec `json:"sqs,omitempty"` | ||
| Drain DrainSpec `json:"drain,omitempty"` | ||
| } | ||
|
|
||
| // SqsSpec defines inputs to SQS "receive messages" requests. | ||
| type SqsSpec struct { | ||
| // https://pkg.go.dev/github.com/aws/[email protected]/service/sqs#ReceiveMessageInput | ||
| AttributeNames []string `json:"attributeNames,omitempty"` | ||
| MaxNumberOfMessages int64 `json:"maxNumberOfMessages,omitempty"` | ||
| MessageAttributeNames []string `json:"messageAttributeNames,omitempty"` | ||
| QueueUrl string `json:"queueUrl,omitempty"` | ||
| VisibilityTimeoutSeconds int64 `json:"visibilityTimeoutSeconds,omitempty"` | ||
| WaitTimeSeconds int64 `json:"waitTimeSeconds,omitempty"` | ||
| } | ||
|
|
||
| // DrainSpec defines inputs to the cordon and drain operations. | ||
| type DrainSpec struct { | ||
| // https://pkg.go.dev/k8s.io/[email protected]/pkg/drain#Helper | ||
| Force bool `json:"force,omitempty"` | ||
| GracePeriodSeconds int `json:"gracePeriodSeconds,omitempty"` | ||
| IgnoreAllDaemonSets bool `json:"ignoreAllDaemonSets,omitempty"` | ||
| DeleteEmptyDirData bool `json:"deleteEmptyDirData,omitempty"` | ||
| TimeoutSeconds int `json:"timeoutSeconds,omitempty"` | ||
| } | ||
|
|
||
| // TerminatorStatus defines the observed state of Terminator | ||
|
|
@@ -58,12 +78,6 @@ func (t *Terminator) SetDefaults(_ context.Context) { | |
| // TODO: actually set defaults | ||
| } | ||
|
|
||
| func (t *Terminator) Validate(_ context.Context) *apis.FieldError { | ||
| // Stubbed to satisfy interface requirements. | ||
| // TODO: actually validate | ||
| return nil | ||
| } | ||
|
|
||
| // TerminatorList contains a list of Terminator | ||
| //+kubebuilder:object:root=true | ||
| type TerminatorList struct { | ||
|
|
||
This file contains hidden or 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,90 @@ | ||
| /* | ||
| Copyright 2022. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License 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 v1alpha1 | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/url" | ||
| "strings" | ||
|
|
||
| "github.com/aws/aws-sdk-go/service/sqs" | ||
|
|
||
| "k8s.io/apimachinery/pkg/util/sets" | ||
|
|
||
| "knative.dev/pkg/apis" | ||
| ) | ||
|
|
||
| var ( | ||
| // https://github.com/aws/aws-sdk-go/blob/v1.38.55/service/sqs/api.go#L3966-L3994 | ||
| knownSqsAttributeNames = sets.NewString(sqs.MessageSystemAttributeName_Values()...) | ||
| ) | ||
|
|
||
| func (t *Terminator) Validate(_ context.Context) (errs *apis.FieldError) { | ||
| return errs.Also( | ||
| apis.ValidateObjectMetadata(t).ViaField("metadata"), | ||
| t.Spec.validate().ViaField("spec"), | ||
| ) | ||
| } | ||
|
|
||
| func (t *TerminatorSpec) validate() (errs *apis.FieldError) { | ||
| return t.Sqs.validate().ViaField("sqs") | ||
| } | ||
|
|
||
| func (s *SqsSpec) validate() (errs *apis.FieldError) { | ||
| for _, attrName := range s.AttributeNames { | ||
| if !knownSqsAttributeNames.Has(attrName) { | ||
| errs = errs.Also(apis.ErrInvalidValue(attrName, "attributeNames")) | ||
| } | ||
| } | ||
|
|
||
| // https://github.com/aws/aws-sdk-go/blob/v1.38.55/service/sqs/api.go#L3996-L3999 | ||
| if s.MaxNumberOfMessages < 1 || 10 < s.MaxNumberOfMessages { | ||
| errs = errs.Also(apis.ErrInvalidValue(s.MaxNumberOfMessages, "maxNumberOfMessages", "must be in range 1-10")) | ||
| } | ||
|
|
||
| // https://github.com/aws/aws-sdk-go/blob/v1.38.55/service/sqs/api.go#L4001-L4021 | ||
| // | ||
| // Simple checks are done below. More indepth checks are left to the SQS client/service. | ||
| for _, attrName := range s.MessageAttributeNames { | ||
| if len(attrName) > 256 { | ||
| errs = errs.Also(apis.ErrInvalidValue(attrName, "messageAttributeNames", "must be 256 characters or less")) | ||
| } | ||
|
|
||
| lcAttrName := strings.ToLower(attrName) | ||
| if strings.HasPrefix(lcAttrName, "aws") || strings.HasPrefix(lcAttrName, "amazon") { | ||
| errs = errs.Also(apis.ErrInvalidValue(attrName, "messageAttributeNames", `must not use reserved prefixes "AWS" or "Amazon"`)) | ||
| } | ||
|
|
||
| if strings.HasPrefix(attrName, ".") || strings.HasSuffix(attrName, ".") { | ||
| errs = errs.Also(apis.ErrInvalidValue(attrName, "messageAttributeNames", "must not begin or end with a period (.)")) | ||
| } | ||
| } | ||
|
|
||
| if _, err := url.Parse(s.QueueUrl); err != nil { | ||
| errs = errs.Also(apis.ErrInvalidValue(s.QueueUrl, "queueUrl", "must be a valid URL")) | ||
| } | ||
|
|
||
| if s.VisibilityTimeoutSeconds < 0 { | ||
| errs = errs.Also(apis.ErrInvalidValue(s.VisibilityTimeoutSeconds, "visibilityTimeoutSeconds", "must be zero or greater")) | ||
| } | ||
|
|
||
| if s.WaitTimeSeconds < 0 { | ||
| errs = errs.Also(apis.ErrInvalidValue(s.WaitTimeSeconds, "waitTimeSeconds", "must be zero or greater")) | ||
| } | ||
|
|
||
| return errs | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.