From commits-return-65262-archive-asf-public=cust-asf.ponee.io@camel.apache.org Wed Sep 19 15:54:27 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 0534318067C for ; Wed, 19 Sep 2018 15:54:26 +0200 (CEST) Received: (qmail 11767 invoked by uid 500); 19 Sep 2018 13:54:26 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 11738 invoked by uid 99); 19 Sep 2018 13:54:26 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Sep 2018 13:54:26 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 6C64B829AB; Wed, 19 Sep 2018 13:54:25 +0000 (UTC) Date: Wed, 19 Sep 2018 13:54:29 +0000 To: "commits@camel.apache.org" Subject: [camel-k] 04/09: fix golint findings for pkg/util/kubernetes MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: nferraro@apache.org In-Reply-To: <153736526530.9411.15267716245483416852@gitbox.apache.org> References: <153736526530.9411.15267716245483416852@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: camel-k X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: c92031dd642afd991cc3de4b7e1c3f1796a7a4ab X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180919135425.6C64B829AB@gitbox.apache.org> 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 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()