Skip to content

Commit

Permalink
Implement helm add & install in helm e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
THUzxj committed Jul 22, 2024
1 parent 51f2794 commit 4859578
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
100 changes: 100 additions & 0 deletions test/e2e/helm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
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() {
BeforeAll(func(ctx context.Context) {
By("helm repo add nfd https://kubernetes-sigs.github.io/node-feature-discovery/charts")
err := manager.RunRepo(helm.WithArgs("add", "nfd", "https://kubernetes-sigs.github.io/node-feature-discovery/charts"))
Expect(err).NotTo(HaveOccurred())
By("helm repo update")
err = manager.RunRepo(helm.WithArgs("update"))
Expect(err).NotTo(HaveOccurred())
})

JustBeforeEach(func(ctx context.Context) {
workingDir, err := os.Getwd()
chartPath := filepath.Join(workingDir, "../../", "deployment", "helm", "node-feature-discovery")
Expect(err).NotTo(HaveOccurred())
By("helm install " + release_name + " " + chartPath + " --namespace " + f.Namespace.Name + " --wait")
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) {
manager := helm.New(framework.TestContext.KubeConfig)
By("helm uninstall " + release_name + " --namespace " + f.Namespace.Name)
err := manager.RunUninstall(
helm.WithReleaseName(release_name),
helm.WithNamespace(f.Namespace.Name),
)
Expect(err).NotTo(HaveOccurred())
})

//
// Test nfd deployed by Helm
//
Context("and nfd deployed by Helm", func() {
It("Deployment is running successfully", Label("Helm"), func(ctx context.Context) {
})
})

})
})

0 comments on commit 4859578

Please sign in to comment.