|
7 | 7 | "crypto/x509" |
8 | 8 | "encoding/pem" |
9 | 9 | "fmt" |
| 10 | + gherrors "github.com/pkg/errors" |
10 | 11 | "os" |
11 | 12 | "reflect" |
12 | 13 | "strings" |
@@ -49,8 +50,9 @@ import ( |
49 | 50 | const ( |
50 | 51 | AgentNamespacePrefix = "open-cluster-management-" |
51 | 52 |
|
52 | | - OperatorNamesapce = "open-cluster-management" |
53 | | - DefaultOperatorName = "klusterlet" |
| 53 | + OperatorNamesapce = "open-cluster-management" |
| 54 | + DefaultOperatorName = "klusterlet" |
| 55 | + AwsIrsaAuthentication = "awsirsa" |
54 | 56 | ) |
55 | 57 |
|
56 | 58 | func format(s string) string { |
@@ -148,6 +150,24 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) { |
148 | 150 | genericclioptionsclusteradm.SpokeMutableFeatureGate, ocmfeature.DefaultSpokeRegistrationFeatureGates), |
149 | 151 | ClientCertExpirationSeconds: o.clientCertExpirationSeconds, |
150 | 152 | } |
| 153 | + |
| 154 | + // set registration auth type |
| 155 | + if o.registrationAuth == AwsIrsaAuthentication { |
| 156 | + rawConfig, err := o.ClusteradmFlags.KubectlFactory.ToRawKubeConfigLoader().RawConfig() |
| 157 | + if err != nil { |
| 158 | + klog.Errorf("unable to load managedcluster kubeconfig: %v", err) |
| 159 | + return err |
| 160 | + } |
| 161 | + |
| 162 | + o.klusterletChartConfig.Klusterlet.RegistrationConfiguration.RegistrationDriver = operatorv1.RegistrationDriver{ |
| 163 | + AuthType: o.registrationAuth, |
| 164 | + AwsIrsa: &operatorv1.AwsIrsa{ |
| 165 | + HubClusterArn: o.hubClusterArn, |
| 166 | + ManagedClusterArn: rawConfig.Contexts[rawConfig.CurrentContext].Cluster, |
| 167 | + }, |
| 168 | + } |
| 169 | + } |
| 170 | + |
151 | 171 | o.klusterletChartConfig.Klusterlet.WorkConfiguration = operatorv1.WorkAgentConfiguration{ |
152 | 172 | FeatureGates: genericclioptionsclusteradm.ConvertToFeatureGateAPI( |
153 | 173 | genericclioptionsclusteradm.SpokeMutableFeatureGate, ocmfeature.DefaultSpokeWorkFeatureGates), |
@@ -293,6 +313,10 @@ func (o *Options) validate() error { |
293 | 313 | return err |
294 | 314 | } |
295 | 315 |
|
| 316 | + if (o.registrationAuth == AwsIrsaAuthentication) && (o.hubClusterArn == "") { |
| 317 | + return gherrors.New("hubClusterArn cannot be empty if registrationAuth type is awsirsa") |
| 318 | + } |
| 319 | + |
296 | 320 | return nil |
297 | 321 | } |
298 | 322 |
|
|
0 commit comments