-
Notifications
You must be signed in to change notification settings - Fork 602
Allow user to use arbitraty userdata #651
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,12 @@ package userdata | |
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"text/template" | ||
|
||
"github.com/pkg/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators" | ||
) | ||
|
||
const ( | ||
|
@@ -90,3 +93,21 @@ func funcMap(funcs map[string]interface{}) template.FuncMap { | |
|
||
return funcMap | ||
} | ||
|
||
func GetUserDataFromSecret(machine *actuators.MachineScope) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to create a unit test case for this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple of suggestions and questions:
|
||
if machine.MachineConfig.UserDataSecret != nil { | ||
userData := []byte{} | ||
userDataSecret, err := machine.CoreClient.Secrets(machine.Namespace()).Get(machine.MachineConfig.UserDataSecret.Name, metav1.GetOptions{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How will this secret be created? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. If you set https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/651/files#diff-7fbfb526ca988417add16e1058fcd340R85 |
||
if err != nil { | ||
return "", errors.Errorf("failed to get userData secret %q", machine.MachineConfig.UserDataSecret.Name) | ||
} | ||
if data, exists := userDataSecret.Data["userData"]; exists { | ||
userData = data | ||
} else { | ||
return "", errors.Errorf("secret %q does not have field %q", machine.MachineConfig.UserDataSecret.Name, "userData") | ||
} | ||
encodedUserData := base64.StdEncoding.EncodeToString(userData) | ||
return encodedUserData, nil | ||
} | ||
return "", nil | ||
} |
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.
is this comment still valid?