generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider: enable k3d based cluster provider
provider: enable failure logs during go install based provider install
- Loading branch information
1 parent
a8e494e
commit 3b76b81
Showing
7 changed files
with
472 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 k3d | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/e2e-framework/klient/wait" | ||
"sigs.k8s.io/e2e-framework/klient/wait/conditions" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/features" | ||
) | ||
|
||
func newDeployment(namespace string, name string, replicaCount int32) *appsv1.Deployment { | ||
podSpec := corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "my-container", | ||
Image: "nginx", | ||
}, | ||
}, | ||
} | ||
return &appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace, Labels: map[string]string{"app": "test-app"}}, | ||
Spec: appsv1.DeploymentSpec{ | ||
Replicas: &replicaCount, | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: map[string]string{"app": "test-app"}, | ||
}, | ||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"app": "test-app"}}, | ||
Spec: podSpec, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func TestK3DCluster(t *testing.T) { | ||
deploymentFeature := features.New("Should be able to create a new deployment in the k3d cluster"). | ||
Assess("Create a new deployment", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context { | ||
deployment := newDeployment(c.Namespace(), "test-deployment", 1) | ||
if err := c.Client().Resources().Create(ctx, deployment); err != nil { | ||
t.Fatal(err) | ||
} | ||
var dep appsv1.Deployment | ||
if err := c.Client().Resources().Get(ctx, "test-deployment", c.Namespace(), &dep); err != nil { | ||
t.Fatal(err) | ||
} | ||
err := wait.For(conditions.New(c.Client().Resources()).DeploymentConditionMatch(&dep, appsv1.DeploymentAvailable, corev1.ConditionTrue), wait.WithTimeout(time.Minute*1)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return context.WithValue(ctx, "test-deployment", &dep) | ||
}). | ||
Feature() | ||
|
||
testEnv.Test(t, deploymentFeature) | ||
} |
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,48 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License 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 k3d | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"sigs.k8s.io/e2e-framework/pkg/env" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
"sigs.k8s.io/e2e-framework/pkg/envfuncs" | ||
"sigs.k8s.io/e2e-framework/support/k3d" | ||
) | ||
|
||
var testEnv env.Environment | ||
|
||
func TestMain(m *testing.M) { | ||
testEnv = env.New() | ||
clusterName := envconf.RandomName("k3d-test", 16) | ||
namespace := envconf.RandomName("k3d-ns", 16) | ||
|
||
testEnv.Setup( | ||
envfuncs.CreateClusterWithOpts(k3d.NewProvider(), clusterName, k3d.WithImage("rancher/k3s:v1.29.6-k3s1")), | ||
envfuncs.CreateNamespace(namespace), | ||
envfuncs.LoadImageToCluster(clusterName, "rancher/k3s:v1.29.6-k3s1", "--verbose", "--mode", "direct"), | ||
) | ||
|
||
testEnv.Finish( | ||
envfuncs.DeleteNamespace(namespace), | ||
envfuncs.DestroyCluster(clusterName), | ||
) | ||
|
||
os.Exit(testEnv.Run(m)) | ||
} |
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
Oops, something went wrong.