Skip to content
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

OCPBUGS-44698: Create AWS clients on every reconcile instead of at initialization #5179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

csrwng
Copy link
Contributor

@csrwng csrwng commented Nov 23, 2024

What this PR does / why we need it:
Moves client creation for the private link endpoint controller into the reconcile loop instead of when the reconciler is initially registered. This allows the controller to recover from initial issues assuming a shared vpc role.

Adds additional error logging when AWS cloud API calls fail.

Which issue(s) this PR fixes (optional, use fixes #<issue_number>(, fixes #<issue_number>, ...) format, where issue_number might be a GitHub issue, or a Jira story:
Fixes #OCPBUGS-44698

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

@openshift-ci openshift-ci bot added the area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release label Nov 23, 2024
Copy link
Contributor

openshift-ci bot commented Nov 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: csrwng

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/needs-area labels Nov 23, 2024
@csrwng csrwng changed the title Create AWS clients on every reconcile instead of at initialization OCPBUGS-44698: Create AWS clients on every reconcile instead of at initialization Nov 23, 2024
@openshift-ci-robot openshift-ci-robot added jira/severity-important Referenced Jira bug's severity is important for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Nov 23, 2024
@openshift-ci-robot
Copy link

@csrwng: This pull request references Jira Issue OCPBUGS-44698, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.18.0) matches configured target version for branch (4.18.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

No GitHub users were found matching the public email listed for the QA contact in Jira (jiezhao@redhat.com), skipping review request.

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

What this PR does / why we need it:
Moves client creation for the private link endpoint controller into the reconcile loop instead of when the reconciler is initially registered. This allows the controller to recover from initial issues assuming a shared vpc role.

Adds additional error logging when AWS cloud API calls fail.

Which issue(s) this PR fixes (optional, use fixes #<issue_number>(, fixes #<issue_number>, ...) format, where issue_number might be a GitHub issue, or a Jira story:
Fixes #OCPBUGS-44698

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

GroupId: aws.String(sgID),
IpPermissions: ingressPermissions,
}); err != nil {
log.Error(err, "failed to sect security group ingress rules", "id", sgID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo sect?
Why are we unconditionally logging here then right below we are logging again via

			if supportawsutil.AWSErrorCode(err) != "InvalidPermission.Duplicate" {
				return fmt.Errorf("failed to set security group ingress rules, code: %s", supportawsutil.AWSErrorCode(err))
			}
			log.Info("WARNING: got duplicate permissions error when setting security group ingress permissions", "sgID", sgID)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo sect?
yes

Will also fix the unconditional logging

@@ -756,14 +861,17 @@ func (r *AWSEndpointServiceReconciler) createSecurityGroup(ctx context.Context,
describeSGInput := &ec2.DescribeSecurityGroupsInput{
GroupIds: []*string{aws.String(sgID)},
}
if err = r.ec2Client.WaitUntilSecurityGroupExistsWithContext(ctx, describeSGInput); err != nil {
if err = ec2Client.WaitUntilSecurityGroupExistsWithContext(ctx, describeSGInput); err != nil {
log.Error(err, "failed to wait for security group to exist", "id", sgID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we logging in addition to the returned error and with different message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that the returned error only contains the error code (it goes in the status of the resource) while the log line includes the full error returned from AWS.

I fixed the different error messages

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for example here we'll log
"failed to wait for security group to exist", "id", sgID"
and the controller runtime will log
"failed to wait for security group to exist (id: %s), code: %s", sgID, supportawsutil.AWSErrorCode(err)"

Seems unncecesary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that the latter will also go into the status of the AWSEndpointService

@@ -513,3 +488,7 @@ func NewStartCommand() *cobra.Command {

return cmd
}

func isAWS() bool {
return os.Getenv("AWS_REGION") != ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be:

func isAWSPrivate() bool {
	return os.Getenv("AWS_REGION") != "" && hcp.Spec.Platform.Type == hyperv1.AWSPlatform
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are no longer retrieving the hcp on startup, but we're always setting AWS_REGION on the CPO when platform.Type == AWS:

switch hc.Spec.Platform.Type {
case hyperv1.AWSPlatform:
deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes,
corev1.Volume{
Name: "cloud-token",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumMemory,
},
},
},
corev1.Volume{
Name: "provider-creds",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: platformaws.ControlPlaneOperatorCredsSecret("").Name,
},
},
})
deployment.Spec.Template.Spec.Containers[0].Env = append(deployment.Spec.Template.Spec.Containers[0].Env,
corev1.EnvVar{
Name: "AWS_SHARED_CREDENTIALS_FILE",
Value: "/etc/provider/credentials",
},
corev1.EnvVar{
Name: "AWS_REGION",
Value: hc.Spec.Platform.AWS.Region,
},
corev1.EnvVar{
Name: "AWS_SDK_LOAD_CONFIG",
Value: "true",
})

So just retrieving the hcp on startup for the same check seemed unnecessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see. Where I was actually trying to get is that I guess we should only run this if we are in aws private, i.e. should we check hcp.spec.EndpointAccess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we can. Since we need the hcp for that, I'll restore the code that fetched it on startup.

if err != nil {
return nil, nil, err
}
if b.assumeEndpointRoleARN != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

// When sharedVPC we need assume these additional roles

?

type clientBuilder struct {
mu sync.Mutex
initialized bool
assumeEndpointRoleARN string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumeSharedVPCEndpointRoleARN
assumeSharedVPCRoute53RoleARN
?

b.mu.Lock()
defer b.mu.Unlock()

if !b.initialized {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make any difference if this func is just

b.warnOnDifferentValues(log, hcp)
b.setFromHCP(hcp)
b.initialized = true

without the conditional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd warn unnecessarily when initially setting the values

}
if !completed {
return ctrl.Result{RequeueAfter: endpointServiceDeletionRequeueDuration}, nil
log.Error(err, "failed to get AWS client, skipping aws endpoint service cleanup")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this introduce a new scenario that wasn't possible before? we remove the finalizer if say a transient issue fails to get the client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only 2 possible errors are that the session cannot be created because env/cfg is incomplete or that the client builder was not initialized from a hcp. Either case is not recoverable with a retry.

@enxebre
Copy link
Member

enxebre commented Nov 26, 2024

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 26, 2024
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 26, 2024
@enxebre
Copy link
Member

enxebre commented Nov 26, 2024

/retest

Moves client creation for the private link endpoint controller into the
reconcile loop instead of when the reconciler is initially registered.
This allows the controller to recover from initial issues assuming a
shared vpc role.

Adds additional error logging when AWS cloud API calls fail.
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 26, 2024
@csrwng
Copy link
Contributor Author

csrwng commented Nov 26, 2024

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 26, 2024
@enxebre
Copy link
Member

enxebre commented Nov 27, 2024

/lgtm
/test e2e-aks

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 27, 2024
@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD da24e17 and 2 for PR HEAD fda98ca in total

Copy link
Contributor

openshift-ci bot commented Nov 27, 2024

@csrwng: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD f2d9716 and 2 for PR HEAD fda98ca in total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release jira/severity-important Referenced Jira bug's severity is important for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants