Collectd Operator Unit Tests
[demo.git] / vnfs / DAaaS / microservices / collectd-operator / pkg / controller / utils / dsutils.go
index d6c60cc..1892b52 100644 (file)
@@ -1,14 +1,27 @@
+/*
+Copyright 2019 Intel Corporation.
+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 utils
 
 import (
        "path/filepath"
-       "strings"
        "strconv"
+       "strings"
 
        onapv1alpha1 "collectd-operator/pkg/apis/onap/v1alpha1"
 
+       appsv1 "k8s.io/api/apps/v1"
        corev1 "k8s.io/api/core/v1"
-       extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
        logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
 )
 
@@ -24,9 +37,9 @@ const (
 )
 
 // RemoveTypesDB - removes TypesDB volumes and volume mounts from collectd pods.
-func RemoveTypesDB(ds *extensionsv1beta1.DaemonSet) {
+func RemoveTypesDB(ds *appsv1.DaemonSet) {
        vols := &ds.Spec.Template.Spec.Volumes
-       for i:=0; i < len(*vols); i++ {
+       for i := 0; i < len(*vols); i++ {
                if (*vols)[i].Name == typesDB {
                        *vols = append((*vols)[:i], (*vols)[i+1:]...)
                        i--
@@ -37,7 +50,7 @@ func RemoveTypesDB(ds *extensionsv1beta1.DaemonSet) {
        for j, container := range *containers {
                if container.Name == collectdContainerName {
                        vms := &(*containers)[j].VolumeMounts
-                       for i:=0; i < len(*vms); i++ {
+                       for i := 0; i < len(*vms); i++ {
                                if (*vms)[i].Name == typesDB {
                                        *vms = append((*vms)[:i], (*vms)[i+1:]...)
                                        i--
@@ -48,7 +61,7 @@ func RemoveTypesDB(ds *extensionsv1beta1.DaemonSet) {
 }
 
 // UpsertTypesDB - Insert/Update TypesDB volumes and volume mounts to collectd pods.
-func UpsertTypesDB(ds *extensionsv1beta1.DaemonSet, cm *corev1.ConfigMap, cr *onapv1alpha1.CollectdGlobal) {
+func UpsertTypesDB(ds *appsv1.DaemonSet, cm *corev1.ConfigMap, cr *onapv1alpha1.CollectdGlobal) {
        typesVM := findMountInfo(cr)
        if *typesVM == nil || len(*typesVM) == 0 {
                return
@@ -81,7 +94,7 @@ func UpsertTypesDB(ds *extensionsv1beta1.DaemonSet, cm *corev1.ConfigMap, cr *on
        for j, container := range *containers {
                if container.Name == collectdContainerName {
                        vms := &(*containers)[j].VolumeMounts
-                       for i:=0; i < len(*vms); i++ {
+                       for i := 0; i < len(*vms); i++ {
                                // Update case (Equivalent to remove and add)
                                if (*vms)[i].Name == typesDB {
                                        *vms = append((*vms)[:i], (*vms)[i+1:]...)
@@ -104,7 +117,7 @@ func findMountInfo(cr *onapv1alpha1.CollectdGlobal) *[]corev1.VolumeMount {
                s := strings.Fields(globalOpt)
                log.V(1).Info(":::::s:::::", "s:", s)
                if s != nil && len(s) != 0 && s[0] == "TypesDB" {
-                       path,_ := strconv.Unquote(s[1])
+                       path, _ := strconv.Unquote(s[1])
                        _, file := filepath.Split(path)
                        log.V(1).Info(":::::file:::::", "s[1]:", path, "file:", file)
                        vm := corev1.VolumeMount{Name: typesDB, MountPath: path, SubPath: file}