Skip to content

Commit

Permalink
Add Helm Test to cover additional attributes introduced in values.yam…
Browse files Browse the repository at this point in the history
…l used during kanister operator installation (#2881)

* Add support for --dry-run in Helm Client

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* refactor app installs to set dryRun as false

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Add support for send output of helm install with dryRun enabled

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Add Helper Functions for Helm Installation Output

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>

* Address review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address lint error

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Initial commit

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Fixed test cases failures

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Added [nit]

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Removed un-used func

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Fix lint error and helm test error

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Addressed review comments. Refactor func to include filter

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address refactoring review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Updated doc comments and removed unnecessary comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Minor refactor

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Address review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Updated test comparison

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Shortened func comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Addressed review comments

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Update helm helper func name and usages

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Addressed review comment

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

---------

Signed-off-by: Rajat Gupta <rajat.gupta@veeam.com>
Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>
Co-authored-by: Rajat Gupta <37516416+r4rajat@users.noreply.github.com>
Co-authored-by: Rajat Gupta <rajat.gupta@veeam.com>
  • Loading branch information
3 people committed May 20, 2024
1 parent 9556d54 commit c9c8ea2
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
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

0 comments on commit c9c8ea2

Please sign in to comment.