You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/09/19 13:54:29 UTC

[camel-k] 04/09: fix golint findings for pkg/util/kubernetes

This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit c92031dd642afd991cc3de4b7e1c3f1796a7a4ab
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Wed Sep 19 11:50:25 2018 +0200

    fix golint findings for pkg/util/kubernetes
---
 pkg/util/kubernetes/config.go    | 10 ++++++----
 pkg/util/kubernetes/loader.go    |  5 +++--
 pkg/util/kubernetes/namespace.go |  6 ++++--
 pkg/util/kubernetes/sanitize.go  |  1 +
 pkg/util/kubernetes/wait.go      | 23 ++++++++++++++++++++++-
 5 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/pkg/util/kubernetes/config.go b/pkg/util/kubernetes/config.go
index 465b96c..b5d7393 100644
--- a/pkg/util/kubernetes/config.go
+++ b/pkg/util/kubernetes/config.go
@@ -18,15 +18,17 @@ limitations under the License.
 package kubernetes
 
 import (
-	"github.com/operator-framework/operator-sdk/pkg/k8sclient"
-	"k8s.io/client-go/tools/clientcmd"
 	"os/user"
 	"path/filepath"
+
+	"github.com/operator-framework/operator-sdk/pkg/k8sclient"
+	"k8s.io/client-go/tools/clientcmd"
 )
 
+// InitKubeClient initialize the k8s client
 func InitKubeClient(kubeconfig string) error {
 	if kubeconfig == "" {
-		kubeconfig = GetDefaultKubeConfigFile()
+		kubeconfig = getDefaultKubeConfigFile()
 	}
 
 	// use the current context in kubeconfig
@@ -39,7 +41,7 @@ func InitKubeClient(kubeconfig string) error {
 	return nil
 }
 
-func GetDefaultKubeConfigFile() string {
+func getDefaultKubeConfigFile() string {
 	usr, err := user.Current()
 	if err != nil {
 		panic(err) // TODO handle error
diff --git a/pkg/util/kubernetes/loader.go b/pkg/util/kubernetes/loader.go
index 7e00bc7..fdc1fb8 100644
--- a/pkg/util/kubernetes/loader.go
+++ b/pkg/util/kubernetes/loader.go
@@ -24,14 +24,15 @@ import (
 	"k8s.io/apimachinery/pkg/util/yaml"
 )
 
+// LoadResourceFromYaml loads a k8s resource from a yaml definition
 func LoadResourceFromYaml(data string) (runtime.Object, error) {
 	role := []byte(data)
-	roleJson, err := yaml.ToJSON(role)
+	roleJSON, err := yaml.ToJSON(role)
 	if err != nil {
 		return nil, err
 	}
 	u := unstructured.Unstructured{}
-	err = u.UnmarshalJSON(roleJson)
+	err = u.UnmarshalJSON(roleJSON)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/util/kubernetes/namespace.go b/pkg/util/kubernetes/namespace.go
index 279f64b..664330c 100644
--- a/pkg/util/kubernetes/namespace.go
+++ b/pkg/util/kubernetes/namespace.go
@@ -18,17 +18,19 @@ limitations under the License.
 package kubernetes
 
 import (
-	"github.com/pkg/errors"
 	"io/ioutil"
+
+	"github.com/pkg/errors"
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/client-go/tools/clientcmd"
 	clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
 	clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest"
 )
 
+// GetClientCurrentNamespace --
 func GetClientCurrentNamespace(kubeconfig string) (string, error) {
 	if kubeconfig == "" {
-		kubeconfig = GetDefaultKubeConfigFile()
+		kubeconfig = getDefaultKubeConfigFile()
 	}
 	if kubeconfig == "" {
 		return "default", nil
diff --git a/pkg/util/kubernetes/sanitize.go b/pkg/util/kubernetes/sanitize.go
index e42c554..3021103 100644
--- a/pkg/util/kubernetes/sanitize.go
+++ b/pkg/util/kubernetes/sanitize.go
@@ -32,6 +32,7 @@ func init() {
 	disallowedChars = regexp.MustCompile("[^a-z0-9-]")
 }
 
+// SanitizeName sanitizes the given name to be compatible with k8s
 func SanitizeName(name string) string {
 	name = strings.Split(name, ".")[0]
 	name = path.Base(name)
diff --git a/pkg/util/kubernetes/wait.go b/pkg/util/kubernetes/wait.go
index 1ce55ee..9ae6948 100644
--- a/pkg/util/kubernetes/wait.go
+++ b/pkg/util/kubernetes/wait.go
@@ -1,20 +1,41 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You 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 kubernetes
 
 import (
+	"time"
+
 	"github.com/operator-framework/operator-sdk/pkg/sdk"
 	"github.com/pkg/errors"
 	"k8s.io/apimachinery/pkg/runtime"
-	"time"
 )
 
+// ResourceRetrieveFunction --
 type ResourceRetrieveFunction func() (interface{}, error)
 
+// ResourceCheckFunction --
 type ResourceCheckFunction func(interface{}) (bool, error)
 
 const (
 	sleepTime = 400 * time.Millisecond
 )
 
+// WaitCondition --
 func WaitCondition(obj runtime.Object, condition ResourceCheckFunction, maxDuration time.Duration) error {
 	start := time.Now()