Skip to content

Commit 815e06a

Browse files
committed
Fix project context for component tests with VEN
1 parent cca0d51 commit 815e06a

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

.github/workflows/common-comp-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ jobs:
206206
working-directory: app-orch-deployment/${{ inputs.component }}
207207
env:
208208
COMPONENT: ${{ inputs.component }}
209+
ORCH_DEFAULT_PASSWORD: ${{ secrets.ORCH_DEFAULT_PASSWORD }}
210+
TEST_ORG_NAME: org-2
211+
TEST_PROJECT_NAME: project-2
212+
TEST_USERNAME: p-edge-manager-2
209213
run: |
210214
echo "Running component tests for $COMPONENT"
211215
make component-test

test-common-utils/pkg/auth/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func SetUpAccessToken(server string) (string, error) {
3737
}
3838
data := url.Values{}
3939
data.Set("client_id", "system-client")
40-
data.Set("username", fmt.Sprintf("%s-edge-mgr", types.SampleProject))
40+
data.Set("username", types.SampleUsername)
4141
data.Set("password", types.KCPass)
4242
data.Set("grant_type", "password")
4343
url := "https://" + server + "/realms/master/protocol/openid-connect/token"

test-common-utils/pkg/deployment/deploy.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"context"
99
"fmt"
1010
"net/http"
11+
"os/exec"
12+
"strings"
1113
"time"
1214

1315
deploymentv1 "github.com/open-edge-platform/app-orch-deployment/app-deployment-manager/api/nbi/v2/deployment/v1"
@@ -164,8 +166,13 @@ func StartDeployment(opts StartDeploymentRequest) (string, int, error) {
164166
if opts.DeploymentType == DeploymentTypeTargeted {
165167
clusterID, err = GetFirstClusterID(opts.AdmClient)
166168
if err != nil {
167-
fmt.Printf("Warning: failed to get cluster ID from API: %v, falling back to env var\n", err)
168-
clusterID = types.GetTestClusterID()
169+
fmt.Printf("Warning: failed to get cluster ID from API: %v\n", err)
170+
// Try kubectl fallback
171+
clusterID, err = GetClusterIDFromKubectl()
172+
if err != nil {
173+
fmt.Printf("Warning: kubectl fallback also failed: %v, using env var\n", err)
174+
clusterID = types.GetTestClusterID()
175+
}
169176
}
170177
}
171178
fmt.Printf("Using cluster ID: %s (type: %s)\n", clusterID, opts.DeploymentType)
@@ -630,3 +637,31 @@ func GetFirstClusterID(client *restClient.ClientWithResponses) (string, error) {
630637

631638
return "", fmt.Errorf("no clusters found after %d retries", maxRetries)
632639
}
640+
641+
// GetClusterIDFromKubectl retrieves the cluster ID using kubectl as a fallback.
642+
// This queries the nexus CRD directly to get the cluster UID.
643+
func GetClusterIDFromKubectl() (string, error) {
644+
// First, get the list of cluster names
645+
// #nosec G204 -- Arguments are controlled within application context.
646+
cmd := exec.Command("kubectl", "get", "clusterinfos.nexus.api.resourcemanager.orchestrator.apis",
647+
"-n", "nexus", "-o", "jsonpath={.items[0].metadata.uid}")
648+
output, err := cmd.Output()
649+
if err != nil {
650+
// Try alternative CRD names
651+
// #nosec G204 -- Arguments are controlled within application context.
652+
cmd = exec.Command("kubectl", "get", "clusters.cluster.orchestrator.apis",
653+
"-A", "-o", "jsonpath={.items[0].metadata.uid}")
654+
output, err = cmd.Output()
655+
if err != nil {
656+
return "", fmt.Errorf("failed to get cluster ID via kubectl: %w", err)
657+
}
658+
}
659+
660+
clusterID := strings.TrimSpace(string(output))
661+
if clusterID == "" {
662+
return "", fmt.Errorf("kubectl returned empty cluster ID")
663+
}
664+
665+
fmt.Printf("Got cluster ID from kubectl: %s\n", clusterID)
666+
return clusterID, nil
667+
}

test-common-utils/pkg/types/common_types.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,46 @@ const (
2626
RetryCount = 20
2727
)
2828

29+
// Default values for org and project names
2930
const (
30-
SampleOrg = "sample-org"
31-
SampleProject = "sample-project"
31+
DefaultSampleOrg = "sample-org"
32+
DefaultSampleProject = "sample-project"
3233
)
3334

35+
// SampleOrg returns the organization name from environment variable or default.
36+
var SampleOrg = getSampleOrg()
37+
38+
// SampleProject returns the project name from environment variable or default.
39+
var SampleProject = getSampleProject()
40+
41+
// SampleUsername returns the test username from environment variable or default.
42+
var SampleUsername = getSampleUsername()
43+
44+
func getSampleOrg() string {
45+
org := os.Getenv("TEST_ORG_NAME")
46+
if org == "" {
47+
return DefaultSampleOrg
48+
}
49+
return org
50+
}
51+
52+
func getSampleProject() string {
53+
project := os.Getenv("TEST_PROJECT_NAME")
54+
if project == "" {
55+
return DefaultSampleProject
56+
}
57+
return project
58+
}
59+
60+
func getSampleUsername() string {
61+
username := os.Getenv("TEST_USERNAME")
62+
if username == "" {
63+
// Default format: {project}-edge-mgr
64+
return getSampleProject() + "-edge-mgr"
65+
}
66+
return username
67+
}
68+
3469
// TestClusterID is the cluster ID used for testing.
3570
// It reads from TEST_CLUSTER_ID environment variable, defaults to "demo-cluster".
3671
var TestClusterID = getTestClusterID()

0 commit comments

Comments
 (0)