-
Notifications
You must be signed in to change notification settings - Fork 288
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
Rufio options #6741
Merged
Merged
Rufio options #6741
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a2b5ff7
Copy Rufio Machine v1alpha1 types from upstream:
jacobweinstock 2eb3549
Fix linting issues
jacobweinstock 6341f88
Add Rufio RPC options to hardware.Machine struct:
jacobweinstock 330f3f5
Add population of options in toRufioMachine:
jacobweinstock 0c86fe8
Name change:
jacobweinstock 0651f64
Enable CLI flags to be mapped to env vars:
jacobweinstock e4357fd
Plumb bmc options through from cli to provider:
jacobweinstock 816bf05
Remove TODO code comment
jacobweinstock 10034b1
Add http.Header env/flag parser, update code comments:
jacobweinstock 70bac63
Fix linting issues
jacobweinstock 77f0b4e
Add BMC env opts:
jacobweinstock 9783af5
Add header flag test
jacobweinstock 11f319f
Add test for MarkHidden
jacobweinstock 32d7e71
Add test case for MarkHidden
jacobweinstock 97fde97
Add tests for the basic aflag types
jacobweinstock 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Package aflag is the eks anywhere flag handling package. | ||
package aflag | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
// Flag defines a CLI flag. | ||
type Flag[T any] struct { | ||
Name string | ||
Short string | ||
Usage string | ||
Default T | ||
} | ||
|
||
// String applies f to fs and writes the value to dst. | ||
func String(f Flag[string], dst *string, fs *pflag.FlagSet) { | ||
switch { | ||
// With short form | ||
case f.Short != "": | ||
fs.StringVarP(dst, f.Name, f.Short, f.Default, f.Usage) | ||
// Without short form | ||
default: | ||
fs.StringVar(dst, f.Name, f.Default, f.Usage) | ||
} | ||
} | ||
|
||
// Bool applies f to fs and writes the value to dst. | ||
func Bool(f Flag[bool], dst *bool, fs *pflag.FlagSet) { | ||
switch { | ||
case f.Short != "": | ||
fs.BoolVarP(dst, f.Name, f.Short, f.Default, f.Usage) | ||
default: | ||
fs.BoolVar(dst, f.Name, f.Default, f.Usage) | ||
} | ||
} | ||
|
||
// StringSlice applies f to fs and writes the value to dst. | ||
func StringSlice(f Flag[[]string], dst *[]string, fs *pflag.FlagSet) { | ||
switch { | ||
case f.Short != "": | ||
fs.StringSliceVarP(dst, f.Name, f.Short, f.Default, f.Usage) | ||
default: | ||
fs.StringSliceVar(dst, f.Name, f.Default, f.Usage) | ||
} | ||
} | ||
|
||
// StringString applies f to fs and writes the value to dst. | ||
func StringString(f Flag[map[string]string], dst *map[string]string, fs *pflag.FlagSet) { | ||
switch { | ||
case f.Short != "": | ||
fs.StringToStringVarP(dst, f.Name, f.Short, f.Default, f.Usage) | ||
default: | ||
fs.StringToStringVar(dst, f.Name, f.Default, f.Usage) | ||
} | ||
} | ||
|
||
// HTTPHeader applies f to fs and writes the value to dst. | ||
func HTTPHeader(f Flag[Header], dst *Header, fs *pflag.FlagSet) { | ||
switch { | ||
case f.Short != "": | ||
fs.VarP(dst, f.Name, f.Short, f.Usage) | ||
default: | ||
fs.Var(dst, f.Name, f.Usage) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
cmd/eksctl-anywhere/cmd/flags/cluster.go → cmd/eksctl-anywhere/cmd/aflag/cluster.go
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,63 @@ | ||
package aflag | ||
|
||
import ( | ||
"encoding/csv" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// Header Value. | ||
type Header http.Header | ||
|
||
// NewHeader returns a new Header pointer. | ||
func NewHeader(h *http.Header) *Header { | ||
return (*Header)(h) | ||
} | ||
|
||
// String returns the string representation of the Header. | ||
func (h *Header) String() string { | ||
if b, err := json.Marshal(h); err == nil { | ||
return string(b) | ||
} | ||
|
||
return "" | ||
} | ||
|
||
// Set sets the value of the Header. | ||
// Format: "a=1;2,b=2;4;5". | ||
func (h *Header) Set(val string) error { | ||
var ss []string | ||
n := strings.Count(val, "=") | ||
switch n { | ||
case 0: | ||
return fmt.Errorf("%s must be formatted as key=value;value", val) | ||
case 1: | ||
ss = append(ss, strings.Trim(val, `"`)) | ||
default: | ||
r := csv.NewReader(strings.NewReader(val)) | ||
var err error | ||
ss, err = r.Read() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
out := make(map[string][]string, len(ss)) | ||
for _, pair := range ss { | ||
kv := strings.SplitN(pair, "=", 2) | ||
if len(kv) != 2 { | ||
return fmt.Errorf("%s must be formatted as key=value;value", pair) | ||
} | ||
out[kv[0]] = strings.Split(kv[1], ";") | ||
} | ||
*h = out | ||
|
||
return nil | ||
} | ||
|
||
// Type returns the flag type. | ||
func (h *Header) Type() string { | ||
return "header" | ||
} |
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,101 @@ | ||
package aflag | ||
|
||
// TinkerbellBootstrapIP is used to override the Tinkerbell IP for serving a Tinkerbell stack | ||
// from an admin machine. | ||
var TinkerbellBootstrapIP = Flag[string]{ | ||
Name: "tinkerbell-bootstrap-ip", | ||
Usage: "The IP used to expose the Tinkerbell stack from the bootstrap cluster", | ||
} | ||
|
||
// TinkerbellBMCConsumerURL is a Rufio RPC provider option. | ||
// ConsumerURL is the URL where an rpc consumer/listener is running and to which we will send and receive all notifications. | ||
var TinkerbellBMCConsumerURL = Flag[string]{ | ||
Name: "tinkerbell-bmc-consumer-url", | ||
Usage: "The URL of a BMC RPC consumer/listener used for BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCHTTPContentType is a Rufio RPC provider option. | ||
// The content type header to use for the rpc request notification. | ||
var TinkerbellBMCHTTPContentType = Flag[string]{ | ||
Name: "tinkerbell-bmc-http-content-type", | ||
Usage: "The HTTP content type used for the RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCHTTPMethod is a Rufio RPC provider option. | ||
// The HTTP method to use for the rpc request notification. | ||
var TinkerbellBMCHTTPMethod = Flag[string]{ | ||
Name: "tinkerbell-bmc-http-method", | ||
Usage: "The HTTP method used for the RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCTimestampHeader is a Rufio RPC provider option. | ||
// The the header name that should contain the timestamp. | ||
// Example: X-BMCLIB-Timestamp (in RFC3339 format) | ||
// . | ||
var TinkerbellBMCTimestampHeader = Flag[string]{ | ||
Name: "tinkerbell-bmc-timestamp-header", | ||
Usage: "The HTTP timestamp header used for the RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCStaticHeaders is a Rufio RPC provider option. | ||
// Predefined headers that will be added to every request (comma separated, values are semicolon separated) | ||
// Example: "X-My-Header=1;2;3,X-Custom-Header=abc;def" | ||
// . | ||
var TinkerbellBMCStaticHeaders = Flag[Header]{ | ||
Name: "tinkerbell-bmc-static-headers", | ||
Usage: "Static HTTP headers added to all RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCSigHeaderName is a Rufio RPC provider option. | ||
// The header name that should contain the signature(s). | ||
// Example: X-BMCLIB-Signature | ||
// . | ||
var TinkerbellBMCSigHeaderName = Flag[string]{ | ||
Name: "tinkerbell-bmc-sig-header-name", | ||
Usage: "The HTTP header name for the HMAC signature used in RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCAppendAlgoToHeaderDisabled is a Rufio RPC provider option. | ||
// decides whether to append the algorithm to the signature header or not. | ||
// Example: X-BMCLIB-Signature becomes X-BMCLIB-Signature-256 | ||
// . | ||
var TinkerbellBMCAppendAlgoToHeaderDisabled = Flag[bool]{ | ||
Name: "tinkerbell-bmc-append-algo-to-header-disabled", | ||
Usage: "This disables appending of the algorithm type to the signature header used in RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCSigIncludedPayloadHeaders is a Rufio RPC provider option. | ||
// The headers whose values will be included in the signature payload. | ||
// Example: given these headers in a request: X-My-Header=123,X-Another=456, | ||
// and IncludedPayloadHeaders := []string{"X-Another"}, the value of "X-Another" | ||
// will be included in the signature payload (comma separated). | ||
var TinkerbellBMCSigIncludedPayloadHeaders = Flag[[]string]{ | ||
Name: "tinkerbell-bmc-sig-included-payload-headers", | ||
Usage: "The HTTP headers to be included in the HMAC signature payload used in RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCPrefixSigDisabled is a Rufio RPC provider option. | ||
// Example: sha256=abc123 ; Determines whether the algorithm will be prefixed to the signature. | ||
var TinkerbellBMCPrefixSigDisabled = Flag[bool]{ | ||
Name: "tinkerbell-bmc-prefix-sig-disabled", | ||
Usage: "This disables prefixing the signature with the algorithm type used in RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCHMACSecrets is a Rufio RPC provider option. | ||
// secrets used for signing the payload, all secrets with used to sign with both sha256 and sha512. | ||
var TinkerbellBMCHMACSecrets = Flag[[]string]{ | ||
Name: "tinkerbell-bmc-hmac-secrets", | ||
Usage: "The secrets used to HMAC sign a payload, used in RPC BMC interactions", | ||
} | ||
|
||
// TinkerbellBMCCustomPayload allows providing a JSON payload that will be used in the RPC request. | ||
var TinkerbellBMCCustomPayload = Flag[string]{ | ||
Name: "tinkerbell-bmc-custom-payload", | ||
Usage: "The custom payload used in RPC BMC interactions, must be used with tinkerbell-bmc-custom-payload-dot-location", | ||
} | ||
|
||
// TinkerbellBMCCustomPayloadDotLocation is the path to where the bmclib RequestPayload{} will be embedded. For example: object.data.body. | ||
var TinkerbellBMCCustomPayloadDotLocation = Flag[string]{ | ||
Name: "tinkerbell-bmc-custom-payload-dot-location", | ||
Usage: "The dot location of the custom payload used in RPC BMC interactions, must be used with tinkerbell-bmc-custom-payload", | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for hiding these?
I am OK with the env/cli variables. Curious if we thought about including these in the cluster config somehow? Historically there's been a strong preference for using the cluster config and this seems like something that could feature on the datacenter config?
@vivek-koppuru @jiayiwang7 @abhinavmpandey08
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for hiding these? These are what i would consider advanced options and not something I would recommend we clutter a cli help message with.
Curious if we thought about including these in the cluster config somehow? Yeah, i did consider it. The concern i have for adding to the cluster config is that i believe we don't understand enough about how/if/when customers will use this functionality. I would prefer to hide it like i did and learn more before adding it to the cluster config where deprecating feels a lot more difficult.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great points, agreed.