Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #28 from jstrachan/changes
Browse files Browse the repository at this point in the history
fix: use the namespace from the requirements for setting up local secrets
  • Loading branch information
jstrachan authored Mar 10, 2020
2 parents eeb823d + 4be2eaf commit 810f8ca
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ module github.com/jenkins-x-labs/helmboot
require (
github.com/banzaicloud/bank-vaults v0.0.0-20190508130850-5673d28c46bd
github.com/cli/cli v0.6.1
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/google/go-cmp v0.3.0
github.com/google/uuid v1.1.1
github.com/heptio/sonobuoy v0.16.0
github.com/jenkins-x/go-scm v1.5.76
github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314
github.com/jenkins-x/jx v0.0.0-20200305083540-7eafabca234c
github.com/jenkins-x/jx v0.0.0-20200310115539-b64ed22fb7af
github.com/jetstack/cert-manager v0.5.2
github.com/knative/serving v0.7.0
github.com/mitchellh/go-homedir v1.1.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ github.com/jenkins-x/go-scm v1.5.76 h1:IMlfD8K+XieU2rvA8Sp2fz6FejhFo6JuUG/Do1SZ9
github.com/jenkins-x/go-scm v1.5.76/go.mod h1:PCT338UhP/pQ0IeEeMEf/hoLTYKcH7qjGEKd7jPkeYg=
github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314 h1:kyBMx/ucSV92S+umX/V6DDaPNynlFFOM9MGJWApltoU=
github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314/go.mod h1:C6j5HgwlHGjRU27W4XCs6jXksqYFo8OdBu+p44jqQeM=
github.com/jenkins-x/jx v0.0.0-20200305083540-7eafabca234c h1:UayD2pQKFKFZzOlJwU71JWJ/lb/AKWuqGmtgQCPd+9k=
github.com/jenkins-x/jx v0.0.0-20200305083540-7eafabca234c/go.mod h1:QZVsigjVZ634iK2TqkIs10yANye4JbBF2bHd3i41U8o=
github.com/jenkins-x/jx v0.0.0-20200310115539-b64ed22fb7af h1:0m9oO/2JTQU3C2FQ62+CLHOm+uUlAuOEiLd/Nh8EAWA=
github.com/jenkins-x/jx v0.0.0-20200310115539-b64ed22fb7af/go.mod h1:QZVsigjVZ634iK2TqkIs10yANye4JbBF2bHd3i41U8o=
github.com/jetstack/cert-manager v0.5.2 h1:qs74mdAprZ5kcCYF3arzmEAZtbt+9HneldSJrk21tKs=
github.com/jetstack/cert-manager v0.5.2/go.mod h1:nbddmhjWxYGt04bxvwVGUSeLhZ2PCyNvd7MpXdq+yWY=
github.com/jinzhu/gorm v0.0.0-20170316141641-572d0a0ab1eb/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo=
Expand Down Expand Up @@ -790,11 +790,13 @@ go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
gocloud.dev v0.9.0 h1:89LfZeDLSO3n9K93v0GbKXkxT5y8CdwxKeJIz8K7W90=
gocloud.dev v0.9.0/go.mod h1:L6ze5BTgwlPiq/4v0A/y7tVqLE/Uu31g8IL3fB09e7I=
Expand Down
15 changes: 14 additions & 1 deletion pkg/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/jenkins-x/jx/pkg/cmd/boot"
"github.com/jenkins-x/jx/pkg/cmd/clients"
"github.com/jenkins-x/jx/pkg/cmd/helper"
"github.com/jenkins-x/jx/pkg/cmd/namespace"
"github.com/jenkins-x/jx/pkg/cmd/opts"
"github.com/jenkins-x/jx/pkg/cmd/templates"
"github.com/jenkins-x/jx/pkg/config"
Expand Down Expand Up @@ -293,7 +294,19 @@ func (o *RunOptions) verifyBootSecret(requirements *config.RequirementsConfig) e

reqNs := requirements.Cluster.Namespace
if reqNs != "" && reqNs != ns {
return errors.Errorf("you are currently in the %s namespace but this cluster needs to be booted in namespace %s. please use 'jx ns %s' to switch namespace", ns, reqNs, reqNs)
log.Logger().Infof("switching to the deployment namespace %s as we currently are in the %s namespace", util.ColorInfo(reqNs), util.ColorInfo(ns))

f := clients.NewFactory()
no := &namespace.NamespaceOptions{}
no.CommonOptions = opts.NewCommonOptionsWithTerm(f, os.Stdin, os.Stdout, os.Stderr)
no.BatchMode = o.BatchMode
no.Args = []string{reqNs}
err = no.Run()
if err != nil {
return errors.Wrapf(err, "failed to switch to namespace %s", reqNs)
}
log.Logger().Infof("switched to the %s namespace", reqNs)
ns = reqNs
}

name := secretmgr.LocalSecret
Expand Down
4 changes: 2 additions & 2 deletions pkg/secretmgr/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewSecretManager(kind string, f jxfactory.Factory, requirements *config.Req
switch kind {
case secretmgr.KindGoogleSecretManager:
// lets populate a local secret after importing/editing the google secret
l, err := local.NewLocalSecretManager(f)
l, err := local.NewLocalSecretManager(f, requirements.Cluster.Namespace)
if err != nil {
return nil, err
}
Expand All @@ -30,7 +30,7 @@ func NewSecretManager(kind string, f jxfactory.Factory, requirements *config.Req
}
return proxy.NewProxySecretManager(g, l), nil
case secretmgr.KindLocal:
return local.NewLocalSecretManager(f)
return local.NewLocalSecretManager(f, requirements.Cluster.Namespace)
case secretmgr.KindFake:
return fake.NewFakeSecretManager(), nil
default:
Expand Down
16 changes: 13 additions & 3 deletions pkg/secretmgr/local/local_secretmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/jenkins-x-labs/helmboot/pkg/secretmgr"
"github.com/jenkins-x/jx/pkg/jxfactory"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -19,12 +20,21 @@ type LocalSecretManager struct {
}

// NewLocalSecretManager uses a Kubernetes Secret to manage secrets
func NewLocalSecretManager(f jxfactory.Factory) (secretmgr.SecretManager, error) {
func NewLocalSecretManager(f jxfactory.Factory, namespace string) (secretmgr.SecretManager, error) {
kubeClient, ns, err := f.CreateKubeClient()
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to create Kube Client")
}
return &LocalSecretManager{KubeClient: kubeClient, Namespace: ns}, nil
if namespace == "" {
namespace = ns
}

// lets verify the namespace is created if it doesn't exist
err = kube.EnsureDevNamespaceCreatedWithoutEnvironment(kubeClient, namespace)
if err != nil {
return nil, errors.Wrapf(err, "failed to ensure dev namespace setup %s", namespace)
}
return &LocalSecretManager{KubeClient: kubeClient, Namespace: namespace}, nil
}

// UpsertSecrets upserts the secrets
Expand Down

0 comments on commit 810f8ca

Please sign in to comment.