-
Notifications
You must be signed in to change notification settings - Fork 37
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
add attachedcluater e2e test #594
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
330429e
add attachedcluater e2e test
LiZhenCheng9527 84d9716
change kurator clusters exist wait time
LiZhenCheng9527 320a72f
add install cert-manager and fluxcd
LiZhenCheng9527 9d15200
use go code to write kurator e2e test
LiZhenCheng9527 b10a840
use commit ID as the VERSION
LiZhenCheng9527 6558d00
fix create kurator-host cluster timeout
LiZhenCheng9527 851e93a
Added script to create two clusters as e2e test environments
LiZhenCheng9527 1bb3d78
Scoping for go test in pkg and cmd
LiZhenCheng9527 31f126f
fix Fixed kurator-member.config file path error
LiZhenCheng9527 fe94542
add fleet status check and delete resource when finish e2e test
LiZhenCheng9527 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 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,33 @@ | ||
name: E2E | ||
on: | ||
pull_request: | ||
jobs: | ||
e2e-test: | ||
runs-on: ubuntu-22.04 | ||
name: E2E Test | ||
timeout-minutes: 40 | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20.x | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Build Clusters | ||
uses: helm/[email protected] | ||
with: | ||
version: v0.20.0 | ||
install_only: true | ||
- name: Set Up Clusters | ||
run: | | ||
hack/e2e-test/build-clusters.sh | ||
- name: Install Helm | ||
uses: azure/setup-helm@v3 | ||
with: | ||
version: v3.10.1 | ||
- name: Init kurator cluster | ||
run: | | ||
hack/e2e-test/install-kurator.sh | ||
- name: fleet-clusters e2e test | ||
run: | | ||
hack/e2e-test/run-e2e.sh |
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,86 @@ | ||
/* | ||
Copyright Kurator 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 e2e | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"kurator.dev/kurator/e2e/resources" | ||
clusterv1a1 "kurator.dev/kurator/pkg/apis/cluster/v1alpha1" | ||
) | ||
|
||
var _ = ginkgo.Describe("[AttachedClusters] AttachedClusters testing", func() { | ||
var ( | ||
namespace string | ||
fleetname string | ||
memberClusterName string | ||
kubeconfigPath string | ||
secret *corev1.Secret | ||
attachedcluster *clusterv1a1.AttachedCluster | ||
) | ||
|
||
ginkgo.BeforeEach(func() { | ||
namespace = "default" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use a random namespace for each test |
||
fleetname = "e2etest" | ||
memberClusterName = "kurator-member" | ||
homeDir, err := os.UserHomeDir() | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
kubeconfigPath = filepath.Join(homeDir, ".kube/kurator-member.config") | ||
|
||
// build secrets use member cluster kubeconfig | ||
kubeconfig, readfileErr := os.ReadFile(kubeconfigPath) | ||
gomega.Expect(readfileErr).ShouldNot(gomega.HaveOccurred()) | ||
data := make(map[string][]byte) | ||
data[memberClusterName] = kubeconfig | ||
secret = resources.NewSecret(namespace, memberClusterName, data) | ||
|
||
// build two attachedclusters | ||
secretKeyRef := clusterv1a1.SecretKeyRef{ | ||
Name: memberClusterName, | ||
Key: memberClusterName, | ||
} | ||
attachedcluster = resources.NewAttachedCluster(namespace, memberClusterName, secretKeyRef) | ||
}) | ||
|
||
ginkgo.It("Create Fleet", func() { | ||
// step 1.create secrets | ||
secretCreateErr := resources.CreateSecret(kubeClient, secret) | ||
gomega.Expect(secretCreateErr).ShouldNot(gomega.HaveOccurred()) | ||
|
||
// step 2.create attachedclusters | ||
attachedCreateErr := resources.CreateAttachedCluster(kuratorClient, attachedcluster) | ||
gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred()) | ||
|
||
time.Sleep(5 * time.Second) | ||
// step 3.create fleet | ||
clusters := []*corev1.ObjectReference{ | ||
{ | ||
Name: memberClusterName, | ||
Kind: "AttachedCluster", | ||
}, | ||
} | ||
fleet := resources.NewFleet(namespace, fleetname, clusters) | ||
fleetCreateErr := resources.CreateFleet(kuratorClient, fleet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we need to check fleet status? |
||
gomega.Expect(fleetCreateErr).ShouldNot(gomega.HaveOccurred()) | ||
}) | ||
}) |
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,44 @@ | ||
/* | ||
Copyright Kurator 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 framework | ||
|
||
import ( | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
// LoadRESTClientConfig creates a rest.Config using the passed kubeconfig. If context is empty, current context in kubeconfig will be used. | ||
func LoadRESTClientConfig(kubeconfig string, context string) (*rest.Config, error) { | ||
loader := &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig} | ||
loadedConfig, err := loader.Load() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if context == "" { | ||
context = loadedConfig.CurrentContext | ||
} | ||
klog.Infof("Use context %v", context) | ||
|
||
return clientcmd.NewNonInteractiveClientConfig( | ||
*loadedConfig, | ||
context, | ||
&clientcmd.ConfigOverrides{}, | ||
loader, | ||
).ClientConfig() | ||
} |
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,65 @@ | ||
/* | ||
Copyright Kurator 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 resources | ||
|
||
import ( | ||
"context" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
clusterv1a1 "kurator.dev/kurator/pkg/apis/cluster/v1alpha1" | ||
kurator "kurator.dev/kurator/pkg/client-go/generated/clientset/versioned" | ||
) | ||
|
||
func NewAttachedCluster(namespace string, name string, config clusterv1a1.SecretKeyRef) *clusterv1a1.AttachedCluster { | ||
return &clusterv1a1.AttachedCluster{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "cluster.kurator.dev/v1alpha1", | ||
Kind: "AttachedCluster", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: namespace, | ||
Name: name, | ||
}, | ||
Spec: clusterv1a1.AttachedClusterSpec{ | ||
Kubeconfig: config, | ||
}, | ||
} | ||
} | ||
|
||
// CreateAttachedCluster create AttachedCluster. | ||
func CreateAttachedCluster(client kurator.Interface, attachedCluster *clusterv1a1.AttachedCluster) error { | ||
_, err := client.ClusterV1alpha1().AttachedClusters(attachedCluster.Namespace).Create(context.TODO(), attachedCluster, metav1.CreateOptions{}) | ||
if err != nil { | ||
if apierrors.IsAlreadyExists(err) { | ||
return UpdateAttachedCluster(client, attachedCluster) | ||
} else { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// UpdateAttachedCluster update AttachedCluster | ||
func UpdateAttachedCluster(client kurator.Interface, attachedCluster *clusterv1a1.AttachedCluster) error { | ||
_, err := client.ClusterV1alpha1().AttachedClusters(attachedCluster.Namespace).Update(context.TODO(), attachedCluster, metav1.UpdateOptions{}) | ||
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,66 @@ | ||
/* | ||
Copyright Kurator 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 resources | ||
|
||
import ( | ||
"context" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
fleetv1a1 "kurator.dev/kurator/pkg/apis/fleet/v1alpha1" | ||
kurator "kurator.dev/kurator/pkg/client-go/generated/clientset/versioned" | ||
) | ||
|
||
func NewFleet(namespace string, name string, clusters []*corev1.ObjectReference) *fleetv1a1.Fleet { | ||
return &fleetv1a1.Fleet{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "fleet.kurator.dev/v1alpha1", | ||
Kind: "Fleet", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: namespace, | ||
Name: name, | ||
}, | ||
Spec: fleetv1a1.FleetSpec{ | ||
Clusters: clusters, | ||
}, | ||
} | ||
} | ||
|
||
// CreateAttachedCluster create AttachedCluster. | ||
func CreateFleet(client kurator.Interface, fleet *fleetv1a1.Fleet) error { | ||
_, err := client.FleetV1alpha1().Fleets(fleet.Namespace).Create(context.TODO(), fleet, metav1.CreateOptions{}) | ||
if err != nil { | ||
if apierrors.IsAlreadyExists(err) { | ||
return UpdateFleet(client, fleet) | ||
} else { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// UpdateAttachedCluster update AttachedCluster | ||
func UpdateFleet(client kurator.Interface, fleet *fleetv1a1.Fleet) error { | ||
_, err := client.FleetV1alpha1().Fleets(fleet.Namespace).Update(context.TODO(), fleet, metav1.UpdateOptions{}) | ||
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,63 @@ | ||
/* | ||
Copyright Kurator 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 resources | ||
|
||
import ( | ||
"context" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// NewSecret will build a secret object. | ||
func NewSecret(namespace string, name string, data map[string][]byte) *corev1.Secret { | ||
return &corev1.Secret{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "Secret", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: namespace, | ||
Name: name, | ||
}, | ||
Data: data, | ||
} | ||
} | ||
|
||
// CreateSecret create Secret. | ||
func CreateSecret(client kubernetes.Interface, secret *corev1.Secret) error { | ||
_, err := client.CoreV1().Secrets(secret.Namespace).Create(context.TODO(), secret, metav1.CreateOptions{}) | ||
if err != nil { | ||
if apierrors.IsAlreadyExists(err) { | ||
return UpdateSecret(client, secret) | ||
} else { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// UpdateSecret update Secret | ||
func UpdateSecret(client kubernetes.Interface, secret *corev1.Secret) error { | ||
_, err := client.CoreV1().Secrets(secret.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{}) | ||
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,17 @@ | ||
/* | ||
Copyright Kurator 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 e2e |
Oops, something went wrong.
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.
we need to cleanup the resources created per test