Skip to content

Commit ad99a1d

Browse files
authored
Merge pull request #3735 from luthermonson/oidc-config
normalize oidc configs to string values for comparison
2 parents 41ecc68 + 5330024 commit ad99a1d

File tree

7 files changed

+82
-59
lines changed

7 files changed

+82
-59
lines changed

pkg/cloud/converters/eks.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,19 @@ func TaintEffectFromSDK(effect string) (expinfrav1.TaintEffect, error) {
148148

149149
func ConvertSDKToIdentityProvider(in *ekscontrolplanev1.OIDCIdentityProviderConfig) *identityprovider.OidcIdentityProviderConfig {
150150
if in != nil {
151+
if in.RequiredClaims == nil {
152+
in.RequiredClaims = make(map[string]string)
153+
}
151154
return &identityprovider.OidcIdentityProviderConfig{
152155
ClientID: in.ClientID,
153-
GroupsClaim: in.GroupsClaim,
154-
GroupsPrefix: in.GroupsPrefix,
156+
GroupsClaim: aws.StringValue(in.GroupsClaim),
157+
GroupsPrefix: aws.StringValue(in.GroupsPrefix),
155158
IdentityProviderConfigName: in.IdentityProviderConfigName,
156159
IssuerURL: in.IssuerURL,
157-
RequiredClaims: aws.StringMap(in.RequiredClaims),
160+
RequiredClaims: in.RequiredClaims,
158161
Tags: in.Tags,
159-
UsernameClaim: in.UsernameClaim,
160-
UsernamePrefix: in.UsernamePrefix,
162+
UsernameClaim: aws.StringValue(in.UsernameClaim),
163+
UsernamePrefix: aws.StringValue(in.UsernamePrefix),
161164
}
162165
}
163166

pkg/cloud/services/eks/identity_provider.go

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,20 @@ func (s *Service) reconcileIdentityProvider(ctx context.Context) error {
4949
}
5050

5151
s.scope.V(2).Info("creating oidc provider plan", "desired", desired, "current", current)
52+
procedures, err := identityprovider.
53+
NewPlan(clusterName, current, desired, s.EKSClient, s.scope.Logger).
54+
Create(ctx)
5255

53-
identityProviderPlan := identityprovider.NewPlan(clusterName, current, desired, s.EKSClient, s.scope.Logger)
54-
55-
procedures, err := identityProviderPlan.Create(ctx)
5656
if err != nil {
5757
s.scope.Error(err, "failed creating eks identity provider plan")
5858
return fmt.Errorf("creating eks identity provider plan: %w", err)
5959
}
60+
61+
// nothing will be done, we can leave
62+
if len(procedures) == 0 {
63+
return nil
64+
}
65+
6066
s.scope.V(2).Info("computed EKS identity provider plan", "numprocs", len(procedures))
6167

6268
// Perform required operations
@@ -73,16 +79,24 @@ func (s *Service) reconcileIdentityProvider(ctx context.Context) error {
7379
return errors.Wrap(err, "getting associated identity provider")
7480
}
7581

76-
if latest != nil {
77-
s.scope.ControlPlane.Status.IdentityProviderStatus = ekscontrolplanev1.IdentityProviderStatus{
78-
ARN: aws.StringValue(latest.IdentityProviderConfigArn),
79-
Status: aws.StringValue(latest.Status),
80-
}
82+
if latest == nil {
83+
return nil
84+
}
8185

82-
err := s.scope.PatchObject()
83-
if err != nil {
84-
return errors.Wrap(err, "updating identity provider status")
85-
}
86+
// don't patch if arn/status is the same
87+
if latest.IdentityProviderConfigArn == s.scope.ControlPlane.Status.IdentityProviderStatus.ARN &&
88+
latest.Status == s.scope.ControlPlane.Status.IdentityProviderStatus.Status {
89+
return nil
90+
}
91+
92+
// idp status has changed, patch the control plane
93+
s.scope.ControlPlane.Status.IdentityProviderStatus = ekscontrolplanev1.IdentityProviderStatus{
94+
ARN: latest.IdentityProviderConfigArn,
95+
Status: latest.Status,
96+
}
97+
98+
if err := s.scope.PatchObject(); err != nil {
99+
return errors.Wrap(err, "updating identity provider status")
86100
}
87101

88102
return nil
@@ -114,16 +128,16 @@ func (s *Service) getAssociatedIdentityProvider(ctx context.Context, clusterName
114128
config := providerconfig.IdentityProviderConfig.Oidc
115129

116130
return &identityprovider.OidcIdentityProviderConfig{
117-
ClientID: *config.ClientId,
118-
GroupsClaim: config.GroupsClaim,
119-
GroupsPrefix: config.GroupsPrefix,
120-
IdentityProviderConfigArn: config.IdentityProviderConfigArn,
121-
IdentityProviderConfigName: *config.IdentityProviderConfigName,
122-
IssuerURL: *config.IssuerUrl,
123-
RequiredClaims: config.RequiredClaims,
124-
Status: config.Status,
131+
ClientID: aws.StringValue(config.ClientId),
132+
GroupsClaim: aws.StringValue(config.GroupsClaim),
133+
GroupsPrefix: aws.StringValue(config.GroupsPrefix),
134+
IdentityProviderConfigArn: aws.StringValue(config.IdentityProviderConfigArn),
135+
IdentityProviderConfigName: aws.StringValue(config.IdentityProviderConfigName),
136+
IssuerURL: aws.StringValue(config.IssuerUrl),
137+
RequiredClaims: aws.StringValueMap(config.RequiredClaims),
138+
Status: aws.StringValue(config.Status),
125139
Tags: converters.MapPtrToMap(config.Tags),
126-
UsernameClaim: config.UsernameClaim,
127-
UsernamePrefix: config.UsernamePrefix,
140+
UsernameClaim: aws.StringValue(config.UsernameClaim),
141+
UsernamePrefix: aws.StringValue(config.UsernamePrefix),
128142
}, nil
129143
}

pkg/eks/identityprovider/plan.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package identityprovider
1919
import (
2020
"context"
2121

22-
"github.com/aws/aws-sdk-go/aws"
2322
"github.com/aws/aws-sdk-go/service/eks"
2423
"github.com/aws/aws-sdk-go/service/eks/eksiface"
2524
"github.com/go-logr/logr"
@@ -58,7 +57,7 @@ func (p *plan) Create(ctx context.Context) ([]planner.Procedure, error) {
5857
if p.desiredIdentityProvider == nil {
5958
// disassociation will also also trigger deletion hence
6059
// we do nothing in case of ConfigStatusDeleting as it will happen eventually
61-
if aws.StringValue(p.currentIdentityProvider.Status) == eks.ConfigStatusActive {
60+
if p.currentIdentityProvider.Status == eks.ConfigStatusActive {
6261
procedures = append(procedures, &DisassociateIdentityProviderConfig{plan: p})
6362
}
6463

@@ -80,7 +79,7 @@ func (p *plan) Create(ctx context.Context) ([]planner.Procedure, error) {
8079
if len(p.desiredIdentityProvider.Tags) == 0 && len(p.currentIdentityProvider.Tags) != 0 {
8180
procedures = append(procedures, &RemoveIdentityProviderTagsProcedure{plan: p})
8281
}
83-
switch aws.StringValue(p.currentIdentityProvider.Status) {
82+
switch p.currentIdentityProvider.Status {
8483
case eks.ConfigStatusActive:
8584
// config active no work to be done
8685
return procedures, nil

pkg/eks/identityprovider/plan_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ func createDesiredIdentityProvider(name string, tags infrav1.Tags) *OidcIdentity
227227

228228
func createCurrentIdentityProvider(name string, arn, status string, tags infrav1.Tags) *OidcIdentityProviderConfig {
229229
config := createDesiredIdentityProvider(name, tags)
230-
config.IdentityProviderConfigArn = aws.String(arn)
231-
config.Status = aws.String(status)
230+
config.IdentityProviderConfigArn = arn
231+
config.Status = status
232232

233233
return config
234234
}
@@ -243,6 +243,11 @@ func createDesiredIdentityProviderRequest(name *string) *eks.OidcIdentityProvide
243243
ClientId: aws.String("clientId"),
244244
IdentityProviderConfigName: name,
245245
IssuerUrl: aws.String("http://IssuerURL.com"),
246+
RequiredClaims: make(map[string]*string),
247+
GroupsClaim: aws.String(""),
248+
GroupsPrefix: aws.String(""),
249+
UsernameClaim: aws.String(""),
250+
UsernamePrefix: aws.String(""),
246251
}
247252
}
248253

pkg/eks/identityprovider/procedures.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ func (a *AssociateIdentityProviderProcedure) Do(ctx context.Context) error {
106106
ClusterName: aws.String(a.plan.clusterName),
107107
Oidc: &eks.OidcIdentityProviderConfigRequest{
108108
ClientId: aws.String(oidc.ClientID),
109-
GroupsClaim: oidc.GroupsClaim,
110-
GroupsPrefix: oidc.GroupsPrefix,
109+
GroupsClaim: aws.String(oidc.GroupsClaim),
110+
GroupsPrefix: aws.String(oidc.GroupsPrefix),
111111
IdentityProviderConfigName: aws.String(oidc.IdentityProviderConfigName),
112112
IssuerUrl: aws.String(oidc.IssuerURL),
113-
RequiredClaims: oidc.RequiredClaims,
114-
UsernameClaim: oidc.UsernameClaim,
115-
UsernamePrefix: oidc.UsernamePrefix,
113+
RequiredClaims: aws.StringMap(oidc.RequiredClaims),
114+
UsernameClaim: aws.String(oidc.UsernameClaim),
115+
UsernamePrefix: aws.String(oidc.UsernamePrefix),
116116
},
117117
}
118118

@@ -139,7 +139,7 @@ func (u *UpdatedIdentityProviderTagsProcedure) Name() string {
139139
func (u *UpdatedIdentityProviderTagsProcedure) Do(ctx context.Context) error {
140140
arn := u.plan.currentIdentityProvider.IdentityProviderConfigArn
141141
_, err := u.plan.eksClient.TagResource(&eks.TagResourceInput{
142-
ResourceArn: arn,
142+
ResourceArn: &arn,
143143
Tags: aws.StringMap(u.plan.desiredIdentityProvider.Tags),
144144
})
145145

@@ -164,8 +164,10 @@ func (r *RemoveIdentityProviderTagsProcedure) Do(ctx context.Context) error {
164164
for key := range r.plan.currentIdentityProvider.Tags {
165165
keys = append(keys, aws.String(key))
166166
}
167+
168+
arn := r.plan.currentIdentityProvider.IdentityProviderConfigArn
167169
_, err := r.plan.eksClient.UntagResource(&eks.UntagResourceInput{
168-
ResourceArn: r.plan.currentIdentityProvider.IdentityProviderConfigArn,
170+
ResourceArn: &arn,
169171
TagKeys: keys,
170172
})
171173

pkg/eks/identityprovider/types.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,61 +17,62 @@ limitations under the License.
1717
package identityprovider
1818

1919
import (
20-
"github.com/google/go-cmp/cmp"
20+
"reflect"
2121

2222
infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta2"
2323
)
2424

25-
// OidcIdentityProviderConfig represents the configuration for an OpenID Connect (OIDC)
26-
// identity provider.
25+
// OidcIdentityProviderConfig represents a normalized version of the configuration for an OpenID Connect (OIDC)
26+
// identity provider configuration. To reconcile the config we are going to get the version from EKS and
27+
// AWSManagedControlPlane and will need to have one consistent version of string values from each API.
2728
type OidcIdentityProviderConfig struct {
2829
ClientID string
29-
GroupsClaim *string
30-
GroupsPrefix *string
31-
IdentityProviderConfigArn *string
30+
GroupsClaim string
31+
GroupsPrefix string
32+
IdentityProviderConfigArn string
3233
IdentityProviderConfigName string
3334
IssuerURL string
34-
RequiredClaims map[string]*string
35-
Status *string
35+
RequiredClaims map[string]string
36+
Status string
3637
Tags infrav1.Tags
37-
UsernameClaim *string
38-
UsernamePrefix *string
38+
UsernameClaim string
39+
UsernamePrefix string
3940
}
4041

4142
func (o *OidcIdentityProviderConfig) IsEqual(other *OidcIdentityProviderConfig) bool {
4243
if o == other {
4344
return true
4445
}
4546

46-
if !cmp.Equal(o.ClientID, other.ClientID) {
47+
if o.ClientID != other.ClientID {
4748
return false
4849
}
4950

50-
if !cmp.Equal(o.GroupsClaim, other.GroupsClaim) {
51+
if o.GroupsClaim != other.GroupsClaim {
5152
return false
5253
}
5354

54-
if !cmp.Equal(o.GroupsPrefix, other.GroupsPrefix) {
55+
if o.GroupsPrefix != other.GroupsPrefix {
5556
return false
5657
}
5758

58-
if !cmp.Equal(o.IdentityProviderConfigName, other.IdentityProviderConfigName) {
59+
if o.IdentityProviderConfigName != other.IdentityProviderConfigName {
5960
return false
6061
}
6162

62-
if !cmp.Equal(o.IssuerURL, other.IssuerURL) {
63+
if o.IssuerURL != other.IssuerURL {
6364
return false
6465
}
6566

66-
if !cmp.Equal(o.RequiredClaims, other.RequiredClaims) {
67+
if !reflect.DeepEqual(o.RequiredClaims, other.RequiredClaims) {
6768
return false
6869
}
6970

70-
if !cmp.Equal(o.UsernameClaim, other.UsernameClaim) {
71+
if o.UsernameClaim != other.UsernameClaim {
7172
return false
7273
}
7374

74-
if !cmp.Equal(o.UsernamePrefix, other.UsernamePrefix) {
75+
if o.UsernamePrefix != other.UsernamePrefix {
7576
return false
7677
}
7778

pkg/eks/identityprovider/types_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package identityprovider
1919
import (
2020
"testing"
2121

22-
"github.com/aws/aws-sdk-go/aws"
2322
"github.com/onsi/gomega"
2423
)
2524

@@ -39,7 +38,7 @@ func TestIdentityProviderEqual(t *testing.T) {
3938
ClientID: "a",
4039
IdentityProviderConfigName: "b",
4140
IssuerURL: "c",
42-
Status: aws.String("e"),
41+
Status: "e",
4342
},
4443
},
4544
}

0 commit comments

Comments
 (0)