Skip to content

Commit

Permalink
Add advanced e2e test suite and add deployment with secrets to it. Th…
Browse files Browse the repository at this point in the history
…is is expected to fail due to: #272. So not invoking it as part of GH workflow
  • Loading branch information
barney-s committed Feb 11, 2025
1 parent da9fc20 commit 0c197e7
Show file tree
Hide file tree
Showing 20 changed files with 582 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ deploy-kind: ko
# Run e2e tests
.PHONY: test-e2e
test-e2e: ## Run e2e tests
go test -v ./test/e2e/...
go test -v ./test/e2e/suites/basic/...

.PHONY: test-e2e-kind
test-e2e-kind: deploy-kind
go test -v ./test/e2e/...
make test-e2e
74 changes: 74 additions & 0 deletions test/e2e/suites/advanced/main_test.go
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)
}
90 changes: 90 additions & 0 deletions test/e2e/suites/advanced/using_secrets_test.go
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
})
*/
}
74 changes: 74 additions & 0 deletions test/e2e/suites/basic/main_test.go
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,13 @@ package basic

import (
"context"
"fmt"
"os"
"testing"

"github.com/stretchr/testify/require"

"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)
}

func TestSimpleDeploymentRGD(t *testing.T) {

tc, err := framework.NewTestCase(t, f, "simple-deployment-rgd")
Expand Down
55 changes: 55 additions & 0 deletions test/e2e/testdata/secrets-in-resources/step0/inputs/rgd.yaml
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
Loading

0 comments on commit 0c197e7

Please sign in to comment.