Skip to content

Commit abb7abb

Browse files
authored
Merge branch 'master' into GITOPS-9682-Create-App-Test
2 parents 430bac8 + 2b779a2 commit abb7abb

5 files changed

Lines changed: 148 additions & 49 deletions

scripts/openshiftci-presubmit-unittests.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,31 @@ cd ../..
2727

2828
# Run unit
2929
make test
30+
31+
# Upload coverage to codecov.io - failures here should not fail the build
32+
(
33+
set +e
34+
CODECOV_TOKEN_FILE="/var/run/codecov-token/CODECOV_TOKEN"
35+
if [[ ! -f "${CODECOV_TOKEN_FILE}" ]]; then
36+
echo "Codecov token not found at ${CODECOV_TOKEN_FILE}, skipping upload"
37+
exit 0
38+
fi
39+
CODECOV_TOKEN="$(cat "${CODECOV_TOKEN_FILE}")"
40+
COMMIT="$(git rev-parse HEAD)"
41+
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
42+
QUERY="token=${CODECOV_TOKEN}&commit=${COMMIT}&branch=${BRANCH}&flags=unit-tests"
43+
44+
# Step 1: request an upload slot; response is two lines: report URL, S3 URL.
45+
RESPONSE=$(curl -sX POST -H 'Accept: text/plain' "https://codecov.io/upload/v4?${QUERY}")
46+
S3_URL=$(echo "${RESPONSE}" | sed -n 2p)
47+
if [[ -z "${S3_URL}" ]]; then
48+
echo "Codecov did not return an upload URL, aborting"
49+
exit 1
50+
fi
51+
52+
# Step 2: PUT the coverage file to GCS (Codecov uses GCS, not AWS S3;
53+
# x-amz-storage-class is not supported and causes a 400).
54+
curl -fiX PUT --data-binary @cover.out \
55+
-H 'Content-Type: text/plain' \
56+
"${S3_URL}"
57+
) || echo "Coverage upload to codecov.io failed, continuing"

test/openshift/e2e/ginkgo/parallel/1-031_validate_toolchain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
100100
} else {
101101
// when running against RC/ released version of gitops
102102
expected_dexVersion = "v2.45.0"
103-
expected_redisVersion = "7.2.11"
103+
expected_redisVersion = "8.2.3"
104104
}
105105

106106
By("locating pods containing toolchain in openshift-gitops")

test/openshift/e2e/ginkgo/parallel/1-095_validate_dex_clientsecret_test.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package parallel
1818

1919
import (
2020
"context"
21-
"strings"
2221

2322
argov1beta1api "github.com/argoproj-labs/argocd-operator/api/v1beta1"
2423
. "github.com/onsi/ginkgo/v2"
@@ -90,30 +89,26 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
9089

9190
By("validating that the Dex Client Secret was copied from dex serviceaccount token secret in to argocd-secret, by the operator")
9291

93-
// To verify the behavior we should first get the token secret name of the dex service account.
92+
// The operator now creates an Opaque secret with a deterministic name for the Dex token
93+
// (via TokenRequest API) instead of using auto-generated kubernetes.io/service-account-token secrets.
94+
// The secret name follows the pattern: <argocd-name>-<dex-sa-name>-token
95+
dexTokenSecretName := "example-argocd-argocd-dex-server-token" // #nosec G101 -- This is a Kubernetes secret name, not a credential
9496

95-
var secretName string
96-
for _, secretData := range serviceAccount.Secrets {
97-
98-
if strings.Contains(secretData.Name, "token") {
99-
secretName = secretData.Name
100-
}
101-
}
102-
Expect(secretName).ToNot(BeEmpty())
103-
104-
// Extract the clientSecret
105-
secretReferencedFromServiceAccount := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: secretName, Namespace: ns.Name}}
106-
Eventually(secretReferencedFromServiceAccount).Should(k8sFixture.ExistByName())
107-
tokenFromSASecret := secretReferencedFromServiceAccount.Data["token"]
108-
Expect(tokenFromSASecret).ToNot(BeEmpty())
97+
// Extract the clientSecret from the Dex token secret
98+
dexTokenSecret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: dexTokenSecretName, Namespace: ns.Name}}
99+
Eventually(dexTokenSecret, "30s", "2s").Should(k8sFixture.ExistByName())
100+
tokenFromDexSecret := dexTokenSecret.Data["token"]
101+
Expect(tokenFromDexSecret).ToNot(BeEmpty())
102+
// Verify the secret also contains an expiry field
103+
Expect(dexTokenSecret.Data["expiry"]).ToNot(BeEmpty())
109104

110105
// actualClientSecret is the value of the secret in argocd-secret where argocd-operator should copy the secret from
111106
argocdSecret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "argocd-secret", Namespace: ns.Name}}
112107
Eventually(argocdSecret).Should(k8sFixture.ExistByName())
113108

114109
actualClientSecret := argocdSecret.Data["oidc.dex.clientSecret"]
115110

116-
Expect(string(actualClientSecret)).To(Equal(string(tokenFromSASecret)), "Dex Client Secret for OIDC is not valid")
111+
Expect(string(actualClientSecret)).To(Equal(string(tokenFromDexSecret)), "Dex Client Secret for OIDC is not valid")
117112

118113
})
119114

test/openshift/e2e/ginkgo/parallel/1-098_validate_dex_clientsecret_deprecated.go

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package parallel
1919
import (
2020
"context"
2121
"fmt"
22-
"strings"
2322

2423
argov1beta1api "github.com/argoproj-labs/argocd-operator/api/v1beta1"
2524
. "github.com/onsi/ginkgo/v2"
@@ -86,40 +85,31 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
8685

8786
By("validating that the Dex Client Secret was copied from dex serviceaccount token secret to argocd-secret, by the operator")
8887
Eventually(func() error {
89-
// Get the service account and find its token secret
90-
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dexServiceAccount), dexServiceAccount)
91-
if err != nil {
92-
return err
93-
}
94-
95-
// Find the token secret from the service account secrets
96-
var tokenSecretName string
97-
for _, secret := range dexServiceAccount.Secrets {
98-
if secret.Name != "" && strings.Contains(secret.Name, "token") {
99-
tokenSecretName = secret.Name
100-
break
101-
}
102-
}
88+
// The operator now creates an Opaque secret with a deterministic name for the Dex token
89+
// (via TokenRequest API) instead of using auto-generated kubernetes.io/service-account-token secrets.
90+
// The secret name follows the pattern: <argocd-name>-<dex-sa-name>-token
91+
dexTokenSecretName := "example-argocd-argocd-dex-server-token" // #nosec G101 -- This is a Kubernetes secret name, not a credential
10392

104-
if tokenSecretName == "" {
105-
return fmt.Errorf("no token secret found for service account %s", dexServiceAccount.Name)
106-
}
107-
108-
// Get the token secret and extract the token
109-
tokenSecret := &corev1.Secret{
93+
// Get the Dex token secret and extract the token
94+
dexTokenSecret := &corev1.Secret{
11095
ObjectMeta: metav1.ObjectMeta{
111-
Name: tokenSecretName,
96+
Name: dexTokenSecretName,
11297
Namespace: namespace.Name,
11398
},
11499
}
115-
err = k8sClient.Get(ctx, client.ObjectKeyFromObject(tokenSecret), tokenSecret)
100+
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(dexTokenSecret), dexTokenSecret)
116101
if err != nil {
117102
return err
118103
}
119104

120-
expectedClientSecret, exists := tokenSecret.Data["token"]
105+
expectedClientSecret, exists := dexTokenSecret.Data["token"]
121106
if !exists {
122-
return fmt.Errorf("token not found in secret %s", tokenSecretName)
107+
return fmt.Errorf("token not found in secret %s", dexTokenSecretName)
108+
}
109+
110+
// Verify the secret also contains an expiry field
111+
if _, exists := dexTokenSecret.Data["expiry"]; !exists {
112+
return fmt.Errorf("expiry not found in secret %s", dexTokenSecretName)
123113
}
124114

125115
// Get the argocd-secret and extract the oidc.dex.clientSecret

test/openshift/e2e/ginkgo/sequential/1-037_validate_applicationset_in_any_namespace_test.go

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
appprojectFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/appproject"
1616
argocdFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd"
1717
clusterroleFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/clusterrole"
18+
configmapFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/configmap"
1819
deploymentFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment"
1920
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
2021
namespaceFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/namespace"
@@ -44,6 +45,10 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
4445
BeforeEach(func() {
4546

4647
fixture.EnsureSequentialCleanSlate()
48+
49+
fixture.SetEnvInOperatorSubscriptionOrDeployment("ARGOCD_CLUSTER_CONFIG_NAMESPACES",
50+
"openshift-gitops, argocd-e2e-cluster-config, appset-argocd, appset-old-ns, appset-new-ns, appset-argocd-clusterrole, appset-target-ns")
51+
4752
k8sClient, _ = utils.GetE2ETestKubeClient()
4853
ctx = context.Background()
4954
})
@@ -62,8 +67,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
6267

6368
It("verifying that ArgoCD CR '.spec.applicationset.sourcenamespaces' and '.spec.sourcenamespaces' correctly control role/rolebindings within the managed namespaces", func() {
6469

65-
fixture.SetEnvInOperatorSubscriptionOrDeployment("ARGOCD_CLUSTER_CONFIG_NAMESPACES", "openshift-gitops, argocd-e2e-cluster-config, appset-argocd, appset-old-ns, appset-new-ns")
66-
6770
By("0) create namespaces: appset-argocd, appset-old-ns, appset-new-ns")
6871

6972
appset_argocdNS, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-argocd")
@@ -746,8 +749,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
746749

747750
By("0) create namespaces: appset-argocd, team-1, team-2, team-frontend, team-backend, other-ns")
748751

749-
fixture.SetEnvInOperatorSubscriptionOrDeployment("ARGOCD_CLUSTER_CONFIG_NAMESPACES", "openshift-gitops, argocd-e2e-cluster-config, appset-argocd")
750-
751752
appset_wildcard_argocdNS, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-argocd")
752753
cleanupFunctions = append(cleanupFunctions, cleanupFunc)
753754

@@ -981,8 +982,6 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
981982

982983
It("verifies ApplicationSet clusterrole rules and creates appset/app in another namespace", func() {
983984

984-
fixture.SetEnvInOperatorSubscriptionOrDeployment("ARGOCD_CLUSTER_CONFIG_NAMESPACES", "openshift-gitops, argocd-e2e-cluster-config, appset-argocd-clusterrole,appset-target-ns")
985-
986985
By("creating Argo CD namespace and target source namespace")
987986
argoNamespace, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-argocd-clusterrole")
988987
cleanupFunctions = append(cleanupFunctions, cleanupFunc)
@@ -1194,5 +1193,92 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
11941193
Eventually(appset).Should(k8sFixture.NotExistByName())
11951194
})
11961195

1196+
It("defaults tokenRef strict mode to true when applicationSet sourceNamespaces are configured", func() {
1197+
appsetArgocdNS, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-argocd")
1198+
cleanupFunctions = append(cleanupFunctions, cleanupFunc)
1199+
1200+
targetNS, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-target-ns")
1201+
cleanupFunctions = append(cleanupFunctions, cleanupFunc)
1202+
1203+
argoCD := &v1beta1.ArgoCD{
1204+
ObjectMeta: metav1.ObjectMeta{
1205+
Name: "tokenref-strict-true",
1206+
Namespace: appsetArgocdNS.Name,
1207+
},
1208+
Spec: v1beta1.ArgoCDSpec{
1209+
ApplicationSet: &v1beta1.ArgoCDApplicationSet{
1210+
SourceNamespaces: []string{targetNS.Name},
1211+
},
1212+
},
1213+
}
1214+
Expect(k8sClient.Create(ctx, argoCD)).To(Succeed())
1215+
1216+
cmdParamsCM := &corev1.ConfigMap{
1217+
ObjectMeta: metav1.ObjectMeta{
1218+
Name: common.ArgoCDCmdParamsConfigMapName,
1219+
Namespace: argoCD.Namespace,
1220+
},
1221+
}
1222+
Eventually(cmdParamsCM, "3m", "5s").Should(configmapFixture.HaveStringDataKeyValue(common.ArgoCDApplicationSetControllerTokenRefStrictModeCmdParamKey, "true"))
1223+
})
1224+
1225+
It("defaults tokenRef strict mode to false when applicationSet sourceNamespaces are empty on create", func() {
1226+
appsetArgocdNS, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-argocd")
1227+
cleanupFunctions = append(cleanupFunctions, cleanupFunc)
1228+
1229+
argoCD := &v1beta1.ArgoCD{
1230+
ObjectMeta: metav1.ObjectMeta{
1231+
Name: "tokenref-strict-false-empty",
1232+
Namespace: appsetArgocdNS.Name,
1233+
},
1234+
Spec: v1beta1.ArgoCDSpec{
1235+
ApplicationSet: &v1beta1.ArgoCDApplicationSet{
1236+
SourceNamespaces: []string{},
1237+
},
1238+
},
1239+
}
1240+
Expect(k8sClient.Create(ctx, argoCD)).To(Succeed())
1241+
1242+
cmdParamsCM := &corev1.ConfigMap{
1243+
ObjectMeta: metav1.ObjectMeta{
1244+
Name: common.ArgoCDCmdParamsConfigMapName,
1245+
Namespace: argoCD.Namespace,
1246+
},
1247+
}
1248+
Eventually(cmdParamsCM, "3m", "5s").Should(configmapFixture.HaveStringDataKeyValue(common.ArgoCDApplicationSetControllerTokenRefStrictModeCmdParamKey, "false"))
1249+
})
1250+
1251+
It("spec.cmdParams overrides tokenRef strict mode default", func() {
1252+
appsetArgocdNS, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-argocd")
1253+
cleanupFunctions = append(cleanupFunctions, cleanupFunc)
1254+
1255+
targetNS, cleanupFunc := fixture.CreateNamespaceWithCleanupFunc("appset-target-ns")
1256+
cleanupFunctions = append(cleanupFunctions, cleanupFunc)
1257+
1258+
argoCD := &v1beta1.ArgoCD{
1259+
ObjectMeta: metav1.ObjectMeta{
1260+
Name: "tokenref-strict-optout",
1261+
Namespace: appsetArgocdNS.Name,
1262+
},
1263+
Spec: v1beta1.ArgoCDSpec{
1264+
ApplicationSet: &v1beta1.ArgoCDApplicationSet{
1265+
SourceNamespaces: []string{targetNS.Name},
1266+
},
1267+
CmdParams: map[string]string{
1268+
common.ArgoCDApplicationSetControllerTokenRefStrictModeCmdParamKey: "false",
1269+
},
1270+
},
1271+
}
1272+
Expect(k8sClient.Create(ctx, argoCD)).To(Succeed())
1273+
1274+
cmdParamsCM := &corev1.ConfigMap{
1275+
ObjectMeta: metav1.ObjectMeta{
1276+
Name: common.ArgoCDCmdParamsConfigMapName,
1277+
Namespace: argoCD.Namespace,
1278+
},
1279+
}
1280+
Eventually(cmdParamsCM, "3m", "5s").Should(configmapFixture.HaveStringDataKeyValue(common.ArgoCDApplicationSetControllerTokenRefStrictModeCmdParamKey, "false"))
1281+
})
1282+
11971283
})
11981284
})

0 commit comments

Comments
 (0)