-
Notifications
You must be signed in to change notification settings - Fork 219
Add E2E test framework and 2 simple tests #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
name: E2E Tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
e2e-kind: | ||
name: E2E Tests (Using KiND) | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache: true | ||
|
||
- name: Install kind | ||
run: go install sigs.k8s.io/kind@latest | ||
|
||
- name: Build and deploy to kind cluster | ||
run: make deploy-kind | ||
|
||
- name: Run e2e tests | ||
run: make test-e2e |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,157 @@ | ||
// 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 framework | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
const ( | ||
// DefaultWaitTimeout is the default timeout for waiting operations | ||
DefaultWaitTimeout = 2 * time.Minute | ||
// DefaultWaitInterval is the default interval for waiting operations | ||
DefaultWaitInterval = 5 * time.Second | ||
) | ||
|
||
// Framework provides utilities for e2e testing | ||
type Framework struct { | ||
// KindCluster is the kind cluster provider (optional) | ||
KindCluster *KindClusterProvider | ||
// Client is the controller-runtime client | ||
Client client.Client | ||
// RESTConfig is the kubernetes rest config | ||
RESTConfig *rest.Config | ||
// Scheme is the runtime scheme | ||
Scheme *runtime.Scheme | ||
} | ||
|
||
// Option is a function that configures a Framework | ||
type Option func(*Framework) error | ||
|
||
// WithKindCluster configures the framework to use a kind cluster | ||
func WithKindCluster(opts ...KindClusterOption) Option { | ||
return func(f *Framework) error { | ||
kindCluster, err := NewKindClusterProvider(opts...) | ||
if err != nil { | ||
return fmt.Errorf("failed to create kind cluster provider: %w", err) | ||
} | ||
f.KindCluster = kindCluster | ||
return nil | ||
} | ||
} | ||
|
||
// WithKubeconfig configures the framework to use an existing kubeconfig | ||
func WithKubeconfig(kubeconfigPath string) Option { | ||
return func(f *Framework) error { | ||
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to build config from kubeconfig: %w", err) | ||
} | ||
f.RESTConfig = config | ||
return nil | ||
} | ||
} | ||
|
||
// New creates a new test framework | ||
func New(opts ...Option) (*Framework, error) { | ||
f := &Framework{} | ||
|
||
// Apply options | ||
for _, opt := range opts { | ||
if err := opt(f); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
// If no cluster provider or kubeconfig is specified, try to use default kubeconfig | ||
if f.KindCluster == nil && f.RESTConfig == nil { | ||
kubeconfig := os.Getenv("KUBECONFIG") | ||
if kubeconfig == "" { | ||
kubeconfig = filepath.Join(os.Getenv("HOME"), ".kube", "config") | ||
} | ||
if err := WithKubeconfig(kubeconfig)(f); err != nil { | ||
return nil, fmt.Errorf("failed to use default kubeconfig: %w", err) | ||
} | ||
} | ||
|
||
return f, nil | ||
} | ||
|
||
// Setup sets up the test framework | ||
func (f *Framework) Setup(ctx context.Context) error { | ||
// Create kind cluster if configured | ||
if f.KindCluster != nil { | ||
if err := f.KindCluster.Create(ctx); err != nil { | ||
return fmt.Errorf("failed to create kind cluster: %w", err) | ||
} | ||
f.RESTConfig = f.KindCluster.GetRESTConfig() | ||
} | ||
|
||
// Create client | ||
client, err := client.New(f.RESTConfig, client.Options{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to create client: %w", err) | ||
} | ||
f.Client = client | ||
|
||
return nil | ||
} | ||
|
||
// Teardown tears down the test framework | ||
func (f *Framework) Teardown(ctx context.Context) error { | ||
// Delete kind cluster if it was created | ||
if f.KindCluster != nil { | ||
if err := f.KindCluster.Delete(ctx); err != nil { | ||
return fmt.Errorf("failed to delete kind cluster: %w", err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// LoadCRDs loads CRDs from the specified directory | ||
func (f *Framework) LoadCRDs(ctx context.Context, crdDir string) error { | ||
// Get CRD paths | ||
crdPaths := []string{ | ||
// kro CRDs | ||
filepath.Join(crdDir, "config", "crd", "bases"), | ||
} | ||
|
||
// Apply CRDs | ||
for _, crdPath := range crdPaths { | ||
if err := ApplyManifests(ctx, f.RESTConfig, crdPath); err != nil { | ||
return fmt.Errorf("failed to apply CRDs from %s: %w", crdPath, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// DeployController deploys the kro controller | ||
func (f *Framework) DeployController(ctx context.Context, manifestDir string) error { | ||
// Apply controller manifests | ||
if err := ApplyManifests(ctx, f.RESTConfig, manifestDir); err != nil { | ||
return fmt.Errorf("failed to apply controller manifests: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the direction here is to have a ClusterProvider interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are parking this PR and switching to Chainsaw as suggested by a community user. We may need cluster creation scripts as part of tests at some point when we move beyond kind only tests.