Skip to content

Commit

Permalink
Rename and expose role
Browse files Browse the repository at this point in the history
  • Loading branch information
mnitchev committed Mar 14, 2024
1 parent b638fcb commit 61afb31
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
11 changes: 6 additions & 5 deletions controllers/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ import (
const Finalizer = "crossplane-config-operator.finalizers.giantswarm.io/config-map-controller"

type ConfigMapReconciler struct {
Client client.Client
BaseDomain string
ManagementClusterRole string
Client client.Client
BaseDomain string
ProviderRole string
AssumeRole string
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -303,12 +304,12 @@ func (r *ConfigMapReconciler) getProviderConfigSpec(accountID string) map[string
"credentials": map[string]interface{}{
"source": "WebIdentity",
"webIdentity": map[string]interface{}{
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/crossplane-assume-role", accountID),
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/%s", accountID, r.AssumeRole),
},
},
"assumeRoleChain": []map[string]interface{}{
{
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/%s", accountID, r.ManagementClusterRole),
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/%s", accountID, r.ProviderRole),
},
},
}
Expand Down
15 changes: 8 additions & 7 deletions controllers/config_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ var _ = Describe("PrefixListEntryReconciler", func() {
"credentials": MatchKeys(IgnoreExtras, Keys{
"source": Equal("WebIdentity"),
"webIdentity": MatchKeys(IgnoreExtras, Keys{
"roleARN": Equal(fmt.Sprintf("arn:aws:iam::%s:role/crossplane-assume-role", accountID)),
"roleARN": Equal(fmt.Sprintf("arn:aws:iam::%s:role/the-assume-role", accountID)),
}),
}),
"assumeRoleChain": ConsistOf(MatchKeys(IgnoreExtras, Keys{
"roleARN": Equal(fmt.Sprintf("arn:aws:iam::%s:role/%s", accountID, "the-role")),
"roleARN": Equal(fmt.Sprintf("arn:aws:iam::%s:role/the-provider-role", accountID)),
})),
})))
}
Expand All @@ -82,9 +82,10 @@ var _ = Describe("PrefixListEntryReconciler", func() {

identity, cluster = createRandomClusterWithIdentity()
reconciler = &controllers.ConfigMapReconciler{
Client: k8sClient,
BaseDomain: "base.domain.io",
ManagementClusterRole: "the-role",
Client: k8sClient,
BaseDomain: "base.domain.io",
AssumeRole: "the-assume-role",
ProviderRole: "the-provider-role",
}
roleARN, err := arn.Parse(identity.Spec.RoleArn)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -149,12 +150,12 @@ var _ = Describe("PrefixListEntryReconciler", func() {
"credentials": map[string]interface{}{
"source": "WebIdentity",
"webIdentity": map[string]interface{}{
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/crossplane-assume-role", someOtherAccount),
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/some-other-assume-role", someOtherAccount),
},
},
"assumeRoleChain": []map[string]interface{}{
{
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/%s", someOtherAccount, "some-other-role"),
"roleARN": fmt.Sprintf("arn:aws:iam::%s:role/some-other-provider-role", someOtherAccount),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ spec:
- /manager
args:
- --leader-elect
- --management-cluster-role={{ .Values.managementClusterRole }}
- --provider-role={{ .Values.providerRole }}
- --assume-role={{ .Values.assumeRole }}
- --base-domain={{ .Values.baseDomain }}
securityContext:
{{- with .Values.securityContext }}
Expand Down
3 changes: 2 additions & 1 deletion helm/aws-crossplane-cluster-config-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pod:
group:
id: "1000"

managementClusterRole: ""
assumeRole: ""
providerRole: ""
baseDomain: ""

# Add seccomp to pod security context
Expand Down
13 changes: 8 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var managementClusterRole string
var assumeRole string
var providerRole string
var baseDomain string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&managementClusterRole, "management-cluster-role", "", "The management cluster role.")
flag.StringVar(&assumeRole, "assume-role", "", "The role used by the aws crossplane provider.")
flag.StringVar(&providerRole, "provider-role", "", "The role used by the aws crossplane provider.")
flag.StringVar(&baseDomain, "base-domain", "", "Management cluster base domain.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
Expand Down Expand Up @@ -84,9 +86,10 @@ func main() {
}

if err = (&controllers.ConfigMapReconciler{
Client: mgr.GetClient(),
BaseDomain: baseDomain,
ManagementClusterRole: managementClusterRole,
Client: mgr.GetClient(),
BaseDomain: baseDomain,
AssumeRole: assumeRole,
ProviderRole: providerRole,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Frigate")
os.Exit(1)
Expand Down

0 comments on commit 61afb31

Please sign in to comment.