-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add advanced e2e test suite and add deployment with secrets to it. Th…
…is is expected to fail due to: #272. So not invoking it as part of GH workflow
- Loading branch information
Showing
20 changed files
with
582 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2025 The Kube Resource Orchestrator Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package advanced | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/kro-run/kro/test/e2e/framework" | ||
) | ||
|
||
var ( | ||
f *framework.Framework | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
// Create framework | ||
var err error | ||
|
||
// Connect to the cluster (or create one) | ||
// Option 1: This uses the ENV provided kubeconfig instead of reading standard paths | ||
/* | ||
kubeconfig := os.Getenv("TEST_KUBECONFIG") | ||
if kubeconfig == "" { | ||
t.Skip("TEST_KUBECONFIG not set") | ||
} | ||
options := framework.WithKubeconfig(kubeconfig) | ||
*/ | ||
|
||
// Option 2: Create a kind cluster. we dont support local image build yet. | ||
/* | ||
framework.WithKindCluster( | ||
framework.WithName("kro-basic-test"), | ||
framework.WithWaitTimeout(5*time.Minute), | ||
*/ | ||
|
||
// Option 3: Do nothing. kubeconfig is loaded from standard path | ||
f, err = framework.New() | ||
if err != nil { | ||
fmt.Printf("failed to create framework: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Setup framework | ||
if err := f.Setup(context.Background()); err != nil { | ||
fmt.Printf("failed to setup framework: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Execute the tests | ||
code := m.Run() | ||
|
||
// Teardown framework | ||
if err := f.Teardown(context.Background()); err != nil { | ||
fmt.Printf("failed to teardown framework: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Exit with the test code | ||
os.Exit(code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2025 The Kube Resource Orchestrator Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package advanced | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kro-run/kro/test/e2e/framework" | ||
) | ||
|
||
func TestSecretsInResources(t *testing.T) { | ||
|
||
tc, err := framework.NewTestCase(t, f, "secrets-in-resources") | ||
require.NoError(t, err) | ||
|
||
// Run the test | ||
// Option 1: Run all steps automatically using the manifests to verify | ||
tc.RunTest(t, func(ctx context.Context) error { | ||
return tc.RunAllSteps(ctx) | ||
}) | ||
|
||
// Option 2: Run steps with custom logic | ||
/* | ||
tc.RunTest(t, func(ctx context.Context) error { | ||
// install the rgd | ||
if err := tc.RunStep(ctx, "step0"); err != nil { | ||
return err | ||
} | ||
// create an instance of the rgd | ||
if err := tc.RunStep(ctx, "step1"); err != nil { | ||
return err | ||
} | ||
// Wait for deployment to be created | ||
err = tc.WaitForResource(ctx, | ||
schema.GroupVersionKind{ | ||
Group: "apps", | ||
Version: "v1", | ||
Kind: "Deployment", | ||
}, | ||
"test-instance", | ||
tc.Namespace, | ||
func(obj *unstructured.Unstructured) bool { | ||
replicas, found, _ := unstructured.NestedInt64(obj.Object, "spec", "replicas") | ||
return found && replicas == 2 | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
// update the instance | ||
if err := tc.RunStep(ctx, "step2"); err != nil { | ||
return err | ||
} | ||
// Wait for deployment to be created | ||
err = tc.WaitForResource(ctx, | ||
schema.GroupVersionKind{ | ||
Group: "apps", | ||
Version: "v1", | ||
Kind: "Deployment", | ||
}, | ||
"test-instance", | ||
tc.Namespace, | ||
func(obj *unstructured.Unstructured) bool { | ||
replicas, found, _ := unstructured.NestedInt64(obj.Object, "spec", "replicas") | ||
return found && replicas == 3 | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}) | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2025 The Kube Resource Orchestrator Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package basic | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/kro-run/kro/test/e2e/framework" | ||
) | ||
|
||
var ( | ||
f *framework.Framework | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
// Create framework | ||
var err error | ||
|
||
// Connect to the cluster (or create one) | ||
// Option 1: This uses the ENV provided kubeconfig instead of reading standard paths | ||
/* | ||
kubeconfig := os.Getenv("TEST_KUBECONFIG") | ||
if kubeconfig == "" { | ||
t.Skip("TEST_KUBECONFIG not set") | ||
} | ||
options := framework.WithKubeconfig(kubeconfig) | ||
*/ | ||
|
||
// Option 2: Create a kind cluster. we dont support local image build yet. | ||
/* | ||
framework.WithKindCluster( | ||
framework.WithName("kro-basic-test"), | ||
framework.WithWaitTimeout(5*time.Minute), | ||
*/ | ||
|
||
// Option 3: Do nothing. kubeconfig is loaded from standard path | ||
f, err = framework.New() | ||
if err != nil { | ||
fmt.Printf("failed to create framework: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Setup framework | ||
if err := f.Setup(context.Background()); err != nil { | ||
fmt.Printf("failed to setup framework: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Execute the tests | ||
code := m.Run() | ||
|
||
// Teardown framework | ||
if err := f.Teardown(context.Background()); err != nil { | ||
fmt.Printf("failed to teardown framework: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Exit with the test code | ||
os.Exit(code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
test/e2e/testdata/secrets-in-resources/step0/inputs/rgd.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
apiVersion: kro.run/v1alpha1 | ||
kind: ResourceGraphDefinition | ||
metadata: | ||
name: deployment-with-secret-rgd | ||
spec: | ||
schema: | ||
apiVersion: v1alpha1 | ||
kind: DeploymentWithSecret | ||
spec: | ||
replicas: integer | 1 | ||
image: string | "nginx:latest" | ||
tokenID: string | ||
tokenSecret: string | ||
resources: | ||
- id: secret | ||
template: | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: ${schema.metadata.name}-secret | ||
type: Opaque | ||
stringData: | ||
bootstrap: "true" | ||
token-id: ${schema.spec.tokenID} | ||
token-secret: ${schema.spec.tokenSecret} | ||
- id: deployment | ||
template: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: ${schema.metadata.name} | ||
spec: | ||
replicas: ${schema.spec.replicas} | ||
selector: | ||
matchLabels: | ||
app: ${schema.metadata.name} | ||
template: | ||
metadata: | ||
labels: | ||
app: ${schema.metadata.name} | ||
spec: | ||
containers: | ||
- name: main | ||
image: ${schema.spec.image} | ||
env: | ||
- name: TOKEN_ID | ||
valueFrom: | ||
secretKeyRef: | ||
name: ${schema.metadata.name}-secret | ||
key: token-id | ||
- name: TOKEN_SECRET | ||
valueFrom: | ||
secretKeyRef: | ||
name: ${schema.metadata.name}-secret | ||
key: token-secret |
Oops, something went wrong.