Skip to content
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 Helm Test to cover additional attributes introduced in values.yaml used during kanister operator installation #2881

Merged
merged 38 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7709520
Add support for --dry-run in Helm Client
r4rajat Apr 16, 2024
8b0b5a8
refactor app installs to set dryRun as false
r4rajat Apr 17, 2024
40c7053
Add support for send output of helm install with dryRun enabled
r4rajat Apr 17, 2024
1d2dcc1
Add Helper Functions for Helm Installation Output
r4rajat May 2, 2024
4d196e0
Merge branch 'master' into add-supprt-for-dry-run-helm-client
r4rajat May 2, 2024
c5f8228
Address review comments
mabhi May 9, 2024
9b30899
Address lint error
mabhi May 9, 2024
672fcac
Initial commit
mabhi May 10, 2024
bef7b7a
Fixed test cases failures
mabhi May 10, 2024
7fb14d5
Address review comments
mabhi May 10, 2024
2b11b89
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 10, 2024
4fe93c4
Address review comments
mabhi May 10, 2024
5753a0d
Added [nit]
mabhi May 10, 2024
eba1990
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 11, 2024
594202a
Address comments
mabhi May 11, 2024
3876341
Address review comments
mabhi May 16, 2024
5820262
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 16, 2024
00b786f
Removed un-used func
mabhi May 16, 2024
115b8dd
Fix lint error and helm test error
mabhi May 16, 2024
7473455
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 16, 2024
0ac108c
Addressed review comments. Refactor func to include filter
mabhi May 16, 2024
ab760d9
Address refactoring review comments
mabhi May 16, 2024
dd907d7
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 16, 2024
29a0a24
Address review comments
mabhi May 16, 2024
68759c9
Updated doc comments and removed unnecessary comments
mabhi May 17, 2024
41381b2
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 17, 2024
d8643b9
Merge branch 'master' into add-supprt-for-dry-run-helm-client
mabhi May 17, 2024
5a2f53c
Minor refactor
mabhi May 17, 2024
9dd2f2a
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 17, 2024
aebe4e6
Address review comments
mabhi May 17, 2024
81e29ad
Updated test comparison
mabhi May 17, 2024
dff1314
Shortened func comments
mabhi May 20, 2024
f6e5d1c
Addressed review comments
mabhi May 20, 2024
09af8e7
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 20, 2024
ababf2c
Update helm helper func name and usages
mabhi May 20, 2024
afe354a
Addressed review comment
mabhi May 20, 2024
8831a70
Merge branch 'add-supprt-for-dry-run-helm-client' into add-helm-test-…
mabhi May 20, 2024
3051fac
Merge branch 'master' into add-helm-test-support-pr-2791
mabhi May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/helm/helm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type k8sObj struct {

type K8sObjectType string

const (
K8sObjectTypeDeployment K8sObjectType = "deployment"
)

type RenderedResource struct {
name string
// renderedManifest holds the dry run raw yaml of the resource.
Expand Down
93 changes: 93 additions & 0 deletions pkg/testing/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"testing"

. "gopkg.in/check.v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

Expand Down Expand Up @@ -106,6 +108,97 @@ func (h *HelmTestSuite) TestResourcesFromManifestAfterDryRunHelmInstall(c *C) {
c.Assert(len(resources) > 0, Equals, true)
}

// TestSelectedDeploymentAttrFromKanisterHelmDryRunInstall test case does a dry run install of the `kanister` helm chart and validates
// use cases for `nodeSelector` and `toleration` attributes in the helmValues.yaml. This function is specific to `deployment` resource.
func (h *HelmTestSuite) TestSelectedDeploymentAttrFromKanisterHelmDryRunInstall(c *C) {
nodeSelector := map[string]string{
"selector-key": "selector-value",
}
toleration := []corev1.Toleration{
{
Key: "taint-key",
Operator: corev1.TolerationOpEqual,
Value: "taint-value",
Effect: corev1.TaintEffectNoSchedule,
},
}

var testCases = []struct {
testName string
helmValues map[string]string
expectedNodeSelector map[string]string
expectedTolerations []corev1.Toleration
}{
{
testName: "Both nodeSelector and tolerations are present",
helmValues: map[string]string{
"bpValidatingWebhook.enabled": "false",
"nodeSelector.selector-key": "selector-value",
"tolerations[0].key": "taint-key",
"tolerations[0].operator": "Equal",
"tolerations[0].value": "taint-value",
"tolerations[0].effect": "NoSchedule",
},
expectedNodeSelector: nodeSelector,
expectedTolerations: toleration,
},
{
testName: "Only nodeSelector is present",
helmValues: map[string]string{
"bpValidatingWebhook.enabled": "false",
"nodeSelector.selector-key": "selector-value",
},
expectedNodeSelector: nodeSelector,
expectedTolerations: nil,
},
{
testName: "Only tolerations is present",
helmValues: map[string]string{
"bpValidatingWebhook.enabled": "false",
"tolerations[0].key": "taint-key",
"tolerations[0].operator": "Equal",
"tolerations[0].value": "taint-value",
"tolerations[0].effect": "NoSchedule",
},
expectedNodeSelector: nil,
expectedTolerations: toleration,
},
{
testName: "Both nodeSelector and tolerations are not present",
helmValues: map[string]string{
"bpValidatingWebhook.enabled": "false",
},
expectedNodeSelector: nil,
expectedTolerations: nil,
},
}
for _, tc := range testCases {
c.Logf("Test name:%s ", tc.testName)
defer func() {
h.helmApp.dryRun = false
}()
// Installing kanister release from local kanister-operator - Dry run"
testApp, err := NewHelmApp(tc.helmValues, kanisterName, "../../../helm/kanister-operator", kanisterName, "", true)
c.Assert(err, IsNil)

out, err := testApp.Install()
c.Assert(err, IsNil)
resources := helm.ResourcesFromRenderedManifest(out, func(kind helm.K8sObjectType) bool {
return kind == helm.K8sObjectTypeDeployment
})
c.Assert(len(resources) > 0, Equals, true)
// Take the deployment resources
deployments, err := helm.K8sObjectsFromRenderedResources[*appsv1.Deployment](resources)
c.Assert(err, IsNil)
// Use only the required deployment
var obj = deployments[h.deploymentName]
c.Assert(obj, NotNil)

c.Assert(obj.Spec.Template.Spec.NodeSelector, DeepEquals, tc.expectedNodeSelector)
c.Assert(obj.Spec.Template.Spec.Tolerations, DeepEquals, tc.expectedTolerations)
}
}

func (h *HelmTestSuite) TearDownSuite(c *C) {
c.Log("Uninstalling chart")
err := h.helmApp.Uninstall()
Expand Down
Loading