Skip to content

Commit

Permalink
Add logging when there's an error
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Feb 24, 2020
1 parent 92eb1a7 commit 07bc4f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -63,6 +63,7 @@ require (
k8s.io/cli-runtime v0.17.0
k8s.io/client-go v0.17.2
k8s.io/helm v2.14.3+incompatible
k8s.io/kubernetes v1.13.0
sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/kustomize/api v0.3.2
sigs.k8s.io/yaml v1.1.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Expand Up @@ -921,6 +921,7 @@ k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/kubernetes v1.13.0 h1:qTfB+u5M92k2fCCCVP2iuhgwwSOv1EkAkvQY1tQODD8=
k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/utils v0.0.0-20190801114015-581e00157fb1/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo=
Expand Down
29 changes: 28 additions & 1 deletion pkg/template/config_context.go
Expand Up @@ -2,6 +2,7 @@ package template

import (
"encoding/base64"
"encoding/json"
"fmt"
"regexp"
"strings"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/pkg/errors"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
"github.com/replicatedhq/kots/pkg/crypto"
"k8s.io/kubernetes/pkg/credentialprovider"
)

var (
Expand Down Expand Up @@ -116,6 +118,7 @@ func (ctx ConfigCtx) FuncMap() template.FuncMap {
"LocalRegistryAddress": ctx.localRegistryAddress,
"LocalImageName": ctx.localImageName,
"LocalRegistryImagePullSecret": ctx.localRegistryImagePullSecret,
"HasLocalRegistry": ctx.hasLocalRegistry,
}
}

Expand Down Expand Up @@ -172,6 +175,10 @@ func (ctx ConfigCtx) localRegistryAddress() string {
}

func (ctx ConfigCtx) localImageName(image string) string {
if ctx.LocalRegistry.Host == "" {
return image
}

_, _, imageName, tag, err := parseImageName(image)
if err != nil {
return ""
Expand All @@ -180,8 +187,28 @@ func (ctx ConfigCtx) localImageName(image string) string {
return fmt.Sprintf("%s/%s:%s", ctx.localRegistryAddress(), imageName, tag)
}

func (ctx ConfigCtx) hasLocalRegistry() bool {
return ctx.LocalRegistry.Host != ""
}

func (ctx ConfigCtx) localRegistryImagePullSecret() string {
return ""
dockerConfigEntry := credentialprovider.DockerConfigEntry{
Username: ctx.LocalRegistry.Username,
Password: ctx.LocalRegistry.Password,
}

dockerConfig := credentialprovider.DockerConfig(map[string]credentialprovider.DockerConfigEntry{
ctx.LocalRegistry.Host: dockerConfigEntry,
})

b, err := json.Marshal(dockerConfig)
if err != nil {
fmt.Printf("%#v\n", err)
return ""
}

encoded := base64.StdEncoding.EncodeToString(b)
return encoded
}

func (ctx ConfigCtx) getConfigOptionValue(itemName string) (string, error) {
Expand Down

0 comments on commit 07bc4f0

Please sign in to comment.