-
Notifications
You must be signed in to change notification settings - Fork 63
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
✨ Initialize hub with aws irsa #465
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ package init | |
import ( | ||
"context" | ||
"fmt" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"os" | ||
"time" | ||
|
||
|
@@ -70,10 +71,15 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) { | |
}, | ||
Tag: bundleVersion.OCM, | ||
} | ||
registrationDrivers, err := getRegistrationDrivers(o) | ||
if err != nil { | ||
return err | ||
} | ||
o.clusterManagerChartConfig.ClusterManager = chart.ClusterManagerConfig{ | ||
RegistrationConfiguration: operatorv1.RegistrationHubConfiguration{ | ||
FeatureGates: genericclioptionsclusteradm.ConvertToFeatureGateAPI( | ||
genericclioptionsclusteradm.HubMutableFeatureGate, ocmfeature.DefaultHubRegistrationFeatureGates), | ||
RegistrationDrivers: registrationDrivers, | ||
}, | ||
WorkConfiguration: operatorv1.WorkConfiguration{ | ||
FeatureGates: genericclioptionsclusteradm.ConvertToFeatureGateAPI( | ||
|
@@ -144,6 +150,13 @@ func (o *Options) validate() error { | |
return fmt.Errorf("registry should not be empty") | ||
} | ||
|
||
validRegistrationDriver := sets.New[string]("csr", "awsirsa") | ||
for _, driver := range o.registrationAuth { | ||
if !validRegistrationDriver.Has(driver) { | ||
return fmt.Errorf("only csr and awsirsa are valid drivers") | ||
} | ||
} | ||
|
||
// If --wait is set, some information during initialize process will print to output, the output would not keep | ||
// machine readable, so this behavior should be disabled | ||
if o.wait && o.output != "text" { | ||
|
@@ -353,3 +366,40 @@ func (o *Options) deploySingletonControlplane(kubeClient kubernetes.Interface) e | |
} | ||
return nil | ||
} | ||
|
||
func getRegistrationDrivers(o *Options) ([]operatorv1.RegistrationDriverHub, 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. could we make it simpler? we should validate and return error when a driver name is not allowed in advance. for _, driver := range o.registrationAuth:
registrationDriver := operatorv1.RegistrationDriverHub{AuthType: driver}
if driver == "awisra" {
...
}
registrationDrivers = append(registrationDrivers, registrationDriver) 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. Done |
||
registrationDrivers := []operatorv1.RegistrationDriverHub{} | ||
var registrationDriver operatorv1.RegistrationDriverHub | ||
|
||
for _, driver := range o.registrationAuth { | ||
if driver == "csr" { | ||
registrationDriver = operatorv1.RegistrationDriverHub{AuthType: driver} | ||
} else if driver == "awsirsa" { | ||
hubClusterArn, err := getHubClusterArn(o) | ||
if err != nil { | ||
return registrationDrivers, err | ||
} | ||
registrationDriver = operatorv1.RegistrationDriverHub{AuthType: driver, HubClusterArn: hubClusterArn} | ||
} | ||
registrationDrivers = append(registrationDrivers, registrationDriver) | ||
} | ||
|
||
return registrationDrivers, nil | ||
} | ||
|
||
func getHubClusterArn(o *Options) (string, error) { | ||
hubClusterArn := o.hubClusterArn | ||
if hubClusterArn == "" { | ||
rawConfig, err := o.ClusteradmFlags.KubectlFactory.ToRawKubeConfigLoader().RawConfig() | ||
if err != nil { | ||
klog.Errorf("unable to load hub cluster kubeconfig: %v", err) | ||
return "", err | ||
} | ||
hubClusterArn = rawConfig.Contexts[rawConfig.CurrentContext].Cluster | ||
if hubClusterArn == "" { | ||
klog.Errorf("hubClusterArn has empty value in kubeconfig") | ||
return "", fmt.Errorf("unable to retrieve hubClusterArn from kubeconfig") | ||
} | ||
} | ||
return hubClusterArn, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
I think you would need to validate this value
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.
Thr validation for this is already added to cluster-manager spec and the validation error is already propagated back to the clusteradm consumer even now.
Is that sufficient?