From a18ce345fc17044c0d36c791052d93deaa1c2b11 Mon Sep 17 00:00:00 2001 From: Xingjian Zhang Date: Sat, 20 Jul 2024 13:48:40 +0000 Subject: [PATCH] Implement helm add & install in helm e2e test --- go.mod | 2 + go.sum | 8 +++- test/e2e/helm_test.go | 91 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 test/e2e/helm_test.go diff --git a/go.mod b/go.mod index a6b1420f50..b7cc5b49c6 100644 --- a/go.mod +++ b/go.mod @@ -106,6 +106,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/stoewer/go-strcase v1.2.0 // indirect github.com/stretchr/objx v0.5.2 // indirect + github.com/vladimirvivien/gexe v0.2.0 // indirect go.etcd.io/etcd/api/v3 v3.5.10 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirect go.etcd.io/etcd/client/v3 v3.5.10 // indirect @@ -148,6 +149,7 @@ require ( k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect k8s.io/mount-utils v0.25.0 // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 // indirect + sigs.k8s.io/e2e-framework v0.4.0 sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect ) diff --git a/go.sum b/go.sum index 1045f9559e..4602133b04 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 h1:6UKoz5ujsI55KNpsJH3UwCq3T8kKbZwNZBNPuTTje8U= github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1/go.mod h1:YvJ2f6MplWDhfxiUC3KpyTy76kYUZA4W3pTv/wdKQ9Y= -github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= -github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= +github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jaypipes/ghw v0.12.0 h1:xU2/MDJfWmBhJnujHY9qwXQLs3DBsf0/Xa9vECY0Tho= @@ -256,6 +256,8 @@ github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= +github.com/vladimirvivien/gexe v0.2.0 h1:nbdAQ6vbZ+ZNsolCgSVb9Fno60kzSuvtzVh6Ytqi/xY= +github.com/vladimirvivien/gexe v0.2.0/go.mod h1:LHQL00w/7gDUKIak24n801ABp8C+ni6eBht9vGVst8w= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -446,6 +448,8 @@ k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSn k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RChhv7P11uhYvCSm5G2GaIi5AIGBS6r4c= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0/go.mod h1:z7+wmGM2dfIiLRfrC6jb5kV2Mq/sK1ZP303cxzkV5Y4= +sigs.k8s.io/e2e-framework v0.4.0 h1:4yYmFDNNoTnazqmZJXQ6dlQF1vrnDbutmxlyvBpC5rY= +sigs.k8s.io/e2e-framework v0.4.0/go.mod h1:JilFQPF1OL1728ABhMlf9huse7h+uBJDXl9YeTs49A8= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= diff --git a/test/e2e/helm_test.go b/test/e2e/helm_test.go new file mode 100644 index 0000000000..5de1d90ba1 --- /dev/null +++ b/test/e2e/helm_test.go @@ -0,0 +1,91 @@ +/* +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 e2e + +import ( + "context" + "os" + "path/filepath" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "k8s.io/kubernetes/test/e2e/framework" + "sigs.k8s.io/e2e-framework/third_party/helm" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + e2epod "k8s.io/kubernetes/test/e2e/framework/pod" + admissionapi "k8s.io/pod-security-admission/api" +) + +// Helm based test suite +var _ = NFDDescribe(Label("helm"), func() { + f := framework.NewDefaultFramework("node-feature-discovery") + // To avoid the error of violating the PodSecurity + f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged + + manager := helm.New(framework.TestContext.KubeConfig) + release_name := "node-feature-discovery" + + Context("when deploying by helm", Ordered, func() { + JustBeforeEach(func(ctx context.Context) { + // Install local nfd chart + workingDir, err := os.Getwd() + chartPath := filepath.Join(workingDir, "../../", "deployment", "helm", "node-feature-discovery") + Expect(err).NotTo(HaveOccurred()) + By("Installing nfd helm chart") + err = manager.RunInstall( + helm.WithName(release_name), + helm.WithNamespace(f.Namespace.Name), + helm.WithChart(chartPath), + helm.WithWait(), + ) + Expect(err).NotTo(HaveOccurred()) + + // Show all pods + pods, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).List(ctx, v1.ListOptions{}) + Expect(err).NotTo(HaveOccurred()) + for _, pod := range pods.Items { + By("Pod name: " + pod.Name) + } + // Get the name of the master pod + masterPods, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).List(ctx, v1.ListOptions{LabelSelector: "role=master"}) + Expect(err).NotTo(HaveOccurred()) + Expect(len(masterPods.Items)).To(Equal(1)) + // Wait for the master pod to be running + Expect(e2epod.WaitTimeoutForPodRunningInNamespace(ctx, f.ClientSet, masterPods.Items[0].Name, f.Namespace.Name, time.Minute)).NotTo(HaveOccurred()) + }) + + AfterEach(func(ctx context.Context) { + // Uninstall nfd + By("Uninstalling nfd helm chart") + err := manager.RunUninstall( + helm.WithReleaseName(release_name), + helm.WithNamespace(f.Namespace.Name), + ) + Expect(err).NotTo(HaveOccurred()) + }) + + Context("and nfd deployed by Helm", func() { + It("Deployment is running successfully", Label("Helm"), func(ctx context.Context) { + }) + + It("Deployment with helm again is running successfully", Label("Helm"), func(ctx context.Context) { + }) + }) + }) +})