-
Notifications
You must be signed in to change notification settings - Fork 0
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
capi-add-tags-to-resources #170
Changes from 6 commits
b2eff2d
4f453c9
5f0de04
60e4bf8
5a0e4b6
f241b63
c3e9491
42f5444
e98f6f0
4f43d4f
bcb03f0
cea6f6a
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ import ( | |
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
capi "sigs.k8s.io/cluster-api/api/v1beta1" | ||
capa "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/giantswarm/irsa-operator/pkg/aws/scope" | ||
|
@@ -95,17 +95,13 @@ func (s *Service) Reconcile(ctx context.Context) error { | |
return err | ||
} | ||
|
||
// Fetch custom tags from Cluster CR | ||
cluster := &capi.Cluster{} | ||
err = s.Client.Get(ctx, types.NamespacedName{Namespace: s.Scope.ClusterNamespace(), Name: s.Scope.ClusterName()}, cluster) | ||
if apierrors.IsNotFound(err) { | ||
// fallthrough | ||
} else if err != nil { | ||
// Fetch custom tags from AWSCluster CR | ||
awsCluster := &capa.AWSCluster{} | ||
err = s.Client.Get(ctx, types.NamespacedName{Namespace: s.Scope.ClusterNamespace(), Name: s.Scope.ClusterName()}, awsCluster) | ||
if err != nil { | ||
return err | ||
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. Should we specifically handle 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. Probably a good idea, yeah 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. I do not think its a good idea to continue if the AWSCluster CR is missing, because in that case either something terrible happened or it's some kind of super early in the creation processes and it would mean we ignore the tags that are supposed to be there. this code feels like it was copied from somewhere where it make sense 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. I removed it on purpose |
||
} | ||
customerTags := key.GetCustomerTags(cluster) | ||
|
||
err = s.S3.CreateTags(s.Scope.BucketName(), customerTags) | ||
err = s.S3.CreateTags(s.Scope.BucketName(), awsCluster.Spec.AdditionalTags) | ||
if err != nil { | ||
ctrlmetrics.Errors.WithLabelValues(s.Scope.Installation(), s.Scope.AccountID(), s.Scope.ClusterName(), s.Scope.ClusterNamespace()).Inc() | ||
s.Scope.Logger().Error(err, "failed to create tags") | ||
|
@@ -122,7 +118,7 @@ func (s *Service) Reconcile(ctx context.Context) error { | |
cloudfrontAliasDomain := s.getCloudFrontAliasDomain() | ||
if cloudfrontAliasDomain != "" { | ||
// Ensure ACM certificate. | ||
certificateArn, err := s.ACM.EnsureCertificate(cloudfrontAliasDomain, customerTags) | ||
certificateArn, err := s.ACM.EnsureCertificate(cloudfrontAliasDomain, awsCluster.Spec.AdditionalTags) | ||
if err != nil { | ||
ctrlmetrics.Errors.WithLabelValues(s.Scope.Installation(), s.Scope.AccountID(), s.Scope.ClusterName(), s.Scope.ClusterNamespace()).Inc() | ||
s.Scope.Logger().Error(err, "failed to create ACM certificate") | ||
|
@@ -180,7 +176,7 @@ func (s *Service) Reconcile(ctx context.Context) error { | |
cloudfrontCertificateARN = *certificateArn | ||
} | ||
|
||
distribution, err = s.Cloudfront.EnsureDistribution(cloudfront.DistributionConfig{CustomerTags: customerTags, Aliases: aliases, CertificateArn: cloudfrontCertificateARN}) | ||
distribution, err = s.Cloudfront.EnsureDistribution(cloudfront.DistributionConfig{CustomerTags: awsCluster.Spec.AdditionalTags, Aliases: aliases, CertificateArn: cloudfrontCertificateARN}) | ||
if err != nil { | ||
ctrlmetrics.Errors.WithLabelValues(s.Scope.Installation(), s.Scope.AccountID(), s.Scope.ClusterName(), s.Scope.ClusterNamespace()).Inc() | ||
s.Scope.Logger().Error(err, "failed to create cloudfront distribution") | ||
|
@@ -313,7 +309,7 @@ func (s *Service) Reconcile(ctx context.Context) error { | |
identityProviderURLs = append(identityProviderURLs, util.EnsureHTTPS(*alias)) | ||
} | ||
|
||
return s.IAM.EnsureOIDCProviders(identityProviderURLs, key.STSUrl(s.Scope.Region()), customerTags) | ||
return s.IAM.EnsureOIDCProviders(identityProviderURLs, key.STSUrl(s.Scope.Region()), awsCluster.Spec.AdditionalTags) | ||
} | ||
err = backoff.Retry(createOIDCProvider, b) | ||
if err != 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.
so we don't mutate the input parameter which may lead to surprises
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.
DeepCopy function does not exists for map[], so doing the ugly copy via
for