Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions test/e2e/admin_credential_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ var _ = Describe("Customer", func() {
}

By("revoking all cluster admin credentials via ARO HCP RP API")
poller, err := clusterClient.BeginRevokeCredentials(ctx, *resourceGroup.Name, clusterName, nil)
Expect(err).NotTo(HaveOccurred())

By("waiting for revocation operation to complete")
_, err = poller.PollUntilDone(ctx, nil)
err = framework.RevokeCredentialsAndWait(ctx, clusterClient, *resourceGroup.Name, clusterName, 10*time.Minute)
Expect(err).NotTo(HaveOccurred())

By("validating all admin credentials now fail after revocation")
Expand Down
95 changes: 69 additions & 26 deletions test/util/framework/hcp_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,18 @@ func (tc *perItOrDescribeTestContext) GetAdminRESTConfigForHCPCluster(
hcpClusterName string,
timeout time.Duration, // this is a POST request, so keep the timeout as it's async
) (*rest.Config, error) {
ctx, cancel := context.WithTimeoutCause(ctx, timeout, fmt.Errorf("timeout '%f' minutes exceeded during GetAdminRESTConfigForHCPCluster for cluster %s in resource group %s", timeout.Minutes(), hcpClusterName, resourceGroupName))
defer cancel()

startTime := time.Now()
defer func() {
finishTime := time.Now()
tc.RecordTestStep("Collect admin credentials for cluster", startTime, finishTime)
}()

adminCredentialRequestPoller, err := hcpClient.BeginRequestAdminCredential(
ctx,
resourceGroupName,
hcpClusterName,
nil,
)
credentialResponse, err := RequestAdminCredentialAndWait(ctx, hcpClient, resourceGroupName, hcpClusterName, timeout)
if err != nil {
return nil, fmt.Errorf("failed to start credential request: %w", err)
}

operationResult, err := adminCredentialRequestPoller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{
Frequency: StandardPollInterval,
})
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
return nil, fmt.Errorf("failed waiting for hcpCluster=%q in resourcegroup=%q to finish getting creds, caused by: %w, error: %w", hcpClusterName, resourceGroupName, context.Cause(ctx), err)
}
return nil, fmt.Errorf("failed waiting for hcpCluster=%q in resourcegroup=%q to finish getting creds: %w", hcpClusterName, resourceGroupName, err)
return nil, err
}

switch m := any(operationResult).(type) {
case hcpsdk20240610preview.HcpOpenShiftClustersClientRequestAdminCredentialResponse:
return readStaticRESTConfig(m.Kubeconfig)
default:
return nil, fmt.Errorf("unknown type %T", m)
}
return readStaticRESTConfig(credentialResponse.Kubeconfig)
}

func readStaticRESTConfig(kubeconfigContent *string) (*rest.Config, error) {
Expand All @@ -128,6 +105,72 @@ func readStaticRESTConfig(kubeconfigContent *string) (*rest.Config, error) {
return ret, nil
}

func RequestAdminCredentialAndWait(
ctx context.Context,
hcpClient *hcpsdk20240610preview.HcpOpenShiftClustersClient,
resourceGroupName string,
hcpClusterName string,
timeout time.Duration,
) (*hcpsdk20240610preview.HcpOpenShiftClustersClientRequestAdminCredentialResponse, error) {
ctx, cancel := context.WithTimeoutCause(ctx, timeout, fmt.Errorf("timeout '%f' minutes exceeded during RequestAdminCredentialAndWait for cluster %s in resource group %s", timeout.Minutes(), hcpClusterName, resourceGroupName))
defer cancel()

poller, err := hcpClient.BeginRequestAdminCredential(ctx, resourceGroupName, hcpClusterName, nil)
if err != nil {
return nil, fmt.Errorf("failed to start credential request for hcpCluster=%q in resourcegroup=%q: %w", hcpClusterName, resourceGroupName, err)
}

operationResult, err := poller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{
Frequency: StandardPollInterval,
})
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
return nil, fmt.Errorf("failed waiting for hcpCluster=%q in resourcegroup=%q to finish getting creds, caused by: %w, error: %w", hcpClusterName, resourceGroupName, context.Cause(ctx), err)
}
return nil, fmt.Errorf("failed waiting for hcpCluster=%q in resourcegroup=%q to finish getting creds: %w", hcpClusterName, resourceGroupName, err)
}

switch m := any(operationResult).(type) {
case hcpsdk20240610preview.HcpOpenShiftClustersClientRequestAdminCredentialResponse:
return &m, nil
default:
return nil, fmt.Errorf("unknown type %T", m)
}
}

func RevokeCredentialsAndWait(
ctx context.Context,
hcpClient *hcpsdk20240610preview.HcpOpenShiftClustersClient,
resourceGroupName string,
hcpClusterName string,
timeout time.Duration,
) error {
ctx, cancel := context.WithTimeoutCause(ctx, timeout, fmt.Errorf("timeout '%f' minutes exceeded during RevokeCredentialsAndWait for cluster %s in resource group %s", timeout.Minutes(), hcpClusterName, resourceGroupName))
defer cancel()

poller, err := hcpClient.BeginRevokeCredentials(ctx, resourceGroupName, hcpClusterName, nil)
if err != nil {
return fmt.Errorf("failed to start credential revocation for hcpCluster=%q in resourcegroup=%q: %w", hcpClusterName, resourceGroupName, err)
}

operationResult, err := poller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{
Frequency: StandardPollInterval,
})
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("failed waiting for hcpCluster=%q in resourcegroup=%q to finish revoking creds, caused by: %w, error: %w", hcpClusterName, resourceGroupName, context.Cause(ctx), err)
}
return fmt.Errorf("failed waiting for hcpCluster=%q in resourcegroup=%q to finish revoking creds: %w", hcpClusterName, resourceGroupName, err)
}

switch m := any(operationResult).(type) {
case hcpsdk20240610preview.HcpOpenShiftClustersClientRevokeCredentialsResponse:
return nil
default:
return fmt.Errorf("unknown type %T", m)
}
}

// DeleteHCPCluster deletes an hcp cluster and waits for the operation to complete
func DeleteHCPCluster(
ctx context.Context,
Expand Down