adding metadata for tracked images

pull/72/head
Karolis Rusenas 2017-07-31 23:50:05 +01:00
parent b8a33c15ca
commit b151b18b01
4 changed files with 9 additions and 90 deletions

View File

@ -12,6 +12,7 @@ import (
log "github.com/Sirupsen/logrus"
)
// ErrKeelConfigNotFound - default error when keel configuration for chart is not defined
var ErrKeelConfigNotFound = errors.New("keel configuration not found")
// getImages - get images from chart values
@ -44,19 +45,6 @@ func getImages(vals chartutil.Values) ([]*types.TrackedImage, error) {
Trigger: keelCfg.Trigger,
}
if imageDetails.ImagePullSecretPath != "" {
secretName, err := getValueAsString(vals, imageDetails.ImagePullSecretPath)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"repository_name": imageDetails.RepositoryPath,
"repository_tag": imageDetails.TagPath,
}).Warn("provider.helm: image pull secret was defined but failed to get it from values.yaml")
} else {
trackedImage.Secrets = []string{secretName}
}
}
images = append(images, trackedImage)
}

View File

@ -27,57 +27,10 @@ keel:
`
var chartValuesBSecret = `
---
image:
imagePullSecret: muchsecrecy
repository: gcr.io/v2-namespace/hello-world
tag: "1.1.0"
keel:
images:
-
imagePullSecret: image.imagePullSecret
repository: image.repository
tag: image.tag
policy: all
trigger: poll
name: "al Rashid"
where:
city: Basrah
title: caliph`
var chartValuesBSecretNoPath = `
---
image:
repository: gcr.io/v2-namespace/hello-world
tag: "1.1.0"
keel:
images:
-
imagePullSecret: image.imagePullSecret
repository: image.repository
tag: image.tag
policy: all
trigger: poll
name: "al Rashid"
where:
city: Basrah
title: caliph`
func Test_getImages(t *testing.T) {
vals, _ := chartutil.ReadValues([]byte(chartValuesA))
img, _ := image.Parse("gcr.io/v2-namespace/hello-world:1.1.0")
valsSecret, err := chartutil.ReadValues([]byte(chartValuesBSecret))
if err != nil {
t.Fatalf("failed to parse chartValuesBSecret")
}
valsSecretNoPath, err := chartutil.ReadValues([]byte(chartValuesBSecretNoPath))
if err != nil {
t.Fatalf("failed to parse chartValuesBSecretNoPath")
}
type args struct {
vals chartutil.Values
}
@ -100,33 +53,6 @@ func Test_getImages(t *testing.T) {
},
wantErr: false,
},
{
name: "hello-world image with secrets",
args: args{
vals: valsSecret,
},
want: []*types.TrackedImage{
&types.TrackedImage{
Image: img,
Trigger: types.TriggerTypePoll,
Secrets: []string{"muchsecrecy"},
},
},
wantErr: false,
},
{
name: "hello-world image with secret but no actual value",
args: args{
vals: valsSecretNoPath,
},
want: []*types.TrackedImage{
&types.TrackedImage{
Image: img,
Trigger: types.TriggerTypePoll,
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View File

@ -70,9 +70,8 @@ type KeelChartConfig struct {
// ImageDetails - image details
type ImageDetails struct {
RepositoryPath string `json:"repository"`
TagPath string `json:"tag"`
ImagePullSecretPath string `json:"imagePullSecret"`
RepositoryPath string `json:"repository"`
TagPath string `json:"tag"`
}
// Provider - helm provider, responsible for managing release updates
@ -150,6 +149,8 @@ func (p *Provider) TrackedImages() ([]*types.TrackedImage, error) {
if cfg.PollSchedule == "" {
cfg.PollSchedule = types.KeelPollDefaultSchedule
}
// used to check pod secrets
selector := fmt.Sprintf("app=%s,release=%s", release.Chart.Metadata.Name, release.Name)
releaseImages, err := getImages(vals)
if err != nil {
@ -162,6 +163,9 @@ func (p *Provider) TrackedImages() ([]*types.TrackedImage, error) {
}
for _, img := range releaseImages {
img.Meta = map[string]string{
"selector": selector,
}
img.Namespace = release.Namespace
img.Provider = ProviderName
trackedImages = append(trackedImages, img)

View File

@ -17,6 +17,7 @@ type TrackedImage struct {
Provider string
Namespace string
Secrets []string
Meta map[string]string // metadata supplied by providers
}
func (i TrackedImage) String() string {