ran through gofmt; removed uneccessary comments; cleaned prometheus test

pull/507/head
Neil Toledo 2020-06-12 16:14:11 -07:00
parent 370779e5b7
commit e7a130d589
34 changed files with 1063 additions and 3834 deletions

View File

@ -90,4 +90,3 @@ func (c *ApprovalContext) Created() string {
c.AddHeader(ApprovalCreatedHeader)
return c.v.CreatedAt.String()
}

View File

@ -3,8 +3,8 @@ package hipchat
import (
"time"
log "github.com/sirupsen/logrus"
"github.com/daneharrigan/hipchat"
log "github.com/sirupsen/logrus"
)
type XmppImplementer interface {

View File

@ -11,8 +11,8 @@ import (
"github.com/keel-hq/keel/bot"
"github.com/keel-hq/keel/constants"
log "github.com/sirupsen/logrus"
h "github.com/daneharrigan/hipchat"
log "github.com/sirupsen/logrus"
)
const connectionAttemptsDefault = 5

View File

@ -14,27 +14,27 @@ func (b *Bot) RequestApproval(req *types.Approval) error {
req.Message,
types.LevelSuccess.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "Approval required!",
Value: req.Message + "\n" + fmt.Sprintf("To vote for change type '%s approve %s' to reject it: '%s reject %s'.", b.name, req.Identifier, b.name, req.Identifier),
Short: false,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", req.VotesReceived, req.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: req.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: req.Identifier,
Short: true,
},
slack.AttachmentField{
{
Title: "Provider",
Value: req.Provider.String(),
Short: true,
@ -50,22 +50,22 @@ func (b *Bot) ReplyToApproval(approval *types.Approval) error {
"All approvals received, thanks for voting!",
types.LevelInfo.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "vote received!",
Value: "Waiting for remaining votes.",
Short: false,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", approval.VotesReceived, approval.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: approval.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: approval.Identifier,
Short: true,
@ -77,27 +77,27 @@ func (b *Bot) ReplyToApproval(approval *types.Approval) error {
"Change was rejected",
types.LevelWarn.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "change rejected",
Value: "Change was rejected.",
Short: false,
},
slack.AttachmentField{
{
Title: "Status",
Value: approval.Status().String(),
Short: true,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", approval.VotesReceived, approval.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: approval.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: approval.Identifier,
Short: true,
@ -109,22 +109,22 @@ func (b *Bot) ReplyToApproval(approval *types.Approval) error {
"All approvals received, thanks for voting!",
types.LevelSuccess.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "update approved!",
Value: "All approvals received, thanks for voting!",
Short: false,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", approval.VotesReceived, approval.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: approval.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: approval.Identifier,
Short: true,

View File

@ -150,7 +150,7 @@ func (b *Bot) postMessage(title, message, color string, fields []slack.Attachmen
params.IconURL = b.getBotUserIconURL()
attachements := []slack.Attachment{
slack.Attachment{
{
Fallback: message,
Color: color,
Fields: fields,

View File

@ -350,7 +350,7 @@ func TestProcessRejectedReply(t *testing.T) {
}
func TestIsApproval(t *testing.T) {
event := &slack.MessageEvent{
Msg: slack.Msg{
Channel: "approvals",

View File

@ -92,11 +92,11 @@ func (s *sender) Send(event types.EventNotification) error {
params.IconURL = constants.KeelLogoURL
attachements := []slack.Attachment{
slack.Attachment{
{
Fallback: event.Message,
Color: event.Level.Color(),
Fields: []slack.AttachmentField{
slack.AttachmentField{
{
Title: event.Type.String(),
Value: event.Message,
Short: false,

View File

@ -45,7 +45,7 @@ func (s *TriggerServer) approvalsHandler(resp http.ResponseWriter, req *http.Req
resp.WriteHeader(http.StatusInternalServerError)
return
}
resp.Write(bts)
}

View File

@ -10,9 +10,9 @@ import (
log "github.com/sirupsen/logrus"
)
// namespace/release name/version
func getIdentifier(namespace, name, version string) string {
return namespace + "/" + name + ":" + version
// namespace/release name:version
func getIdentifier(plan *UpdatePlan) string {
return fmt.Sprintf("%s/%s:%s", plan.Namespace, plan.Name, plan.NewVersion)
}
func (p *Provider) checkForApprovals(event *types.Event, plans []*UpdatePlan) (approvedPlans []*UpdatePlan) {
@ -24,6 +24,7 @@ func (p *Provider) checkForApprovals(event *types.Event, plans []*UpdatePlan) (a
"error": err,
"release_name": plan.Name,
"namespace": plan.Namespace,
"version": plan.NewVersion,
}).Error("provider.helm: failed to check approval status for deployment")
continue
}
@ -36,7 +37,7 @@ func (p *Provider) checkForApprovals(event *types.Event, plans []*UpdatePlan) (a
// updateComplete is called after we successfully update resource
func (p *Provider) updateComplete(plan *UpdatePlan) error {
return p.approvalManager.Archive(getIdentifier(plan.Namespace, plan.Name, plan.NewVersion))
return p.approvalManager.Archive(getIdentifier(plan))
}
func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error) {
@ -44,7 +45,7 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
return true, nil
}
identifier := getIdentifier(plan.Namespace, plan.Name, plan.NewVersion)
identifier := getIdentifier(plan)
// checking for existing approval
existing, err := p.approvalManager.Get(identifier)

File diff suppressed because it is too large Load Diff

View File

@ -443,7 +443,6 @@ func getValueAsString(vals chartutil.Values, path string) (string, error) {
}
func values(chart *hapi_chart.Chart, config *hapi_chart.Config) (chartutil.Values, error) {
// func CoalesceValues(chrt *chart.Chart, vals *chart.Config) (Values, error) {
return chartutil.CoalesceValues(chart, config)
}

View File

@ -118,7 +118,7 @@ keel:
fakeImpl := &fakeImplementer{
listReleasesResponse: &rls.ListReleasesResponse{
Releases: []*hapi_release5.Release{
&hapi_release5.Release{
{
Name: "release-1",
Chart: &chart.Chart{
Values: &chart.Config{Raw: chartVals},
@ -164,7 +164,7 @@ func TestGetChartPolicyFromProm(t *testing.T) {
fakeImpl := &fakeImplementer{
listReleasesResponse: &rls.ListReleasesResponse{
Releases: []*hapi_release5.Release{
&hapi_release5.Release{
{
Name: "release-1",
Chart: &chart.Chart{
Values: &chart.Config{Raw: promChartValues},
@ -232,7 +232,7 @@ keel:
fakeImpl := &fakeImplementer{
listReleasesResponse: &rls.ListReleasesResponse{
Releases: []*hapi_release5.Release{
&hapi_release5.Release{
{
Name: "release-1",
Chart: &chart.Chart{
Values: &chart.Config{Raw: chartVals},
@ -275,7 +275,7 @@ image2:
fakeImpl := &fakeImplementer{
listReleasesResponse: &rls.ListReleasesResponse{
Releases: []*hapi_release5.Release{
&hapi_release5.Release{
{
Name: "release-1",
Chart: &chart.Chart{
Values: &chart.Config{Raw: chartVals},
@ -326,7 +326,7 @@ keel:
fakeImpl := &fakeImplementer{
listReleasesResponse: &rls.ListReleasesResponse{
Releases: []*hapi_release5.Release{
&hapi_release5.Release{
{
Name: "release-1",
Chart: &chart.Chart{
Values: &chart.Config{Raw: chartVals},
@ -384,7 +384,7 @@ func TestGetPolicyFromConfig(t *testing.T) {
func TestGetImagesFromConfig(t *testing.T) {
vals, err := testingConfigYaml(&KeelChartConfig{Policy: "all", Images: []ImageDetails{
ImageDetails{
{
RepositoryPath: "repopath",
TagPath: "tagpath",
},
@ -427,14 +427,14 @@ keel:
`
myChart := &chart.Chart{
Values: &chart.Config{Raw: chartVals},
Values: &chart.Config{Raw: chartVals},
Metadata: &chart.Metadata{Name: "app-x"},
}
fakeImpl := &fakeImplementer{
listReleasesResponse: &rls.ListReleasesResponse{
Releases: []*hapi_release5.Release{
&hapi_release5.Release{
{
Name: "release-1",
Chart: myChart,
Config: &chart.Config{Raw: ""},
@ -443,8 +443,6 @@ keel:
},
}
approver, teardown := approver()
defer teardown()
provider := NewProvider(fakeImpl, &fakeSender{}, approver)
@ -598,7 +596,7 @@ keel:
MatchPreRelease: true,
Trigger: types.TriggerTypeDefault,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag"},
{RepositoryPath: "image.repository", TagPath: "image.tag"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeAll, true),
},
@ -612,7 +610,7 @@ keel:
Trigger: types.TriggerTypeDefault,
NotificationChannels: []string{"chan1", "chan2"},
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag"},
{RepositoryPath: "image.repository", TagPath: "image.tag"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeAll, true),
},
@ -626,7 +624,7 @@ keel:
Trigger: types.TriggerTypePoll,
PollSchedule: "@every 30m",
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag", ImagePullSecret: "such-secret"},
{RepositoryPath: "image.repository", TagPath: "image.tag", ImagePullSecret: "such-secret"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, true),
},
@ -639,7 +637,7 @@ keel:
MatchPreRelease: false,
Trigger: types.TriggerTypeDefault,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag"},
{RepositoryPath: "image.repository", TagPath: "image.tag"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeAll, false),
},
@ -683,7 +681,7 @@ keel:
fakeImpl := &fakeImplementer{
listReleasesResponse: &rls.ListReleasesResponse{
Releases: []*hapi_release5.Release{
&hapi_release5.Release{
{
Name: "release-1",
Chart: &chart.Chart{
Values: &chart.Config{Raw: chartVals},

View File

@ -65,17 +65,17 @@ keel:
`
helloWorldChart := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesPolicyForce},
Values: &hapi_chart.Config{Raw: chartValuesPolicyForce},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldChartPolicyMajor := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesPolicyMajor},
Values: &hapi_chart.Config{Raw: chartValuesPolicyMajor},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldChartPolicyMajorReleaseNotes := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesPolicyForceReleaseNotes},
Values: &hapi_chart.Config{Raw: chartValuesPolicyForceReleaseNotes},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
@ -114,7 +114,7 @@ keel:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{
{
RepositoryPath: "image.repository",
TagPath: "image.tag",
},
@ -147,7 +147,7 @@ keel:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{
{
RepositoryPath: "image.repository",
TagPath: "image.tag",
ReleaseNotes: "https://github.com/keel-hq/keel/releases",
@ -274,25 +274,25 @@ image:
`
helloWorldChart := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesA},
Values: &hapi_chart.Config{Raw: chartValuesA},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNonSemverChart := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesB},
Values: &hapi_chart.Config{Raw: chartValuesB},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNonSemverNoForceChart := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesNonSemverNoForce},
Values: &hapi_chart.Config{Raw: chartValuesNonSemverNoForce},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNoTagChart := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesNoTag},
Values: &hapi_chart.Config{Raw: chartValuesNoTag},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNoKeelCfg := &hapi_chart.Chart{
Values: &hapi_chart.Config{Raw: chartValuesNoKeelCfg},
Values: &hapi_chart.Config{Raw: chartValuesNoKeelCfg},
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
@ -332,7 +332,7 @@ image:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag"},
{RepositoryPath: "image.repository", TagPath: "image.tag"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeAll, true),
},
@ -389,7 +389,7 @@ image:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag"},
{RepositoryPath: "image.repository", TagPath: "image.tag"},
},
Plc: policy.NewForcePolicy(false),
},
@ -433,7 +433,7 @@ image:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository"},
{RepositoryPath: "image.repository"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, true),
},

View File

@ -10,9 +10,9 @@ import (
log "github.com/sirupsen/logrus"
)
// namespace/release name/version
func getIdentifier(namespace, name, version string) string {
return namespace + "/" + name + ":" + version
// namespace/release name:version
func getIdentifier(plan *UpdatePlan) string {
return fmt.Sprintf("%s/%s:%s", plan.Namespace, plan.Name, plan.NewVersion)
}
func (p *Provider) checkForApprovals(event *types.Event, plans []*UpdatePlan) (approvedPlans []*UpdatePlan) {
@ -36,7 +36,7 @@ func (p *Provider) checkForApprovals(event *types.Event, plans []*UpdatePlan) (a
// updateComplete is called after we successfully update resource
func (p *Provider) updateComplete(plan *UpdatePlan) error {
return p.approvalManager.Archive(getIdentifier(plan.Namespace, plan.Name, plan.NewVersion))
return p.approvalManager.Archive(getIdentifier(plan))
}
func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error) {
@ -44,7 +44,7 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
return true, nil
}
identifier := getIdentifier(plan.Namespace, plan.Name, plan.NewVersion)
identifier := getIdentifier(plan)
// checking for existing approval
existing, err := p.approvalManager.Get(identifier)

View File

@ -61,7 +61,6 @@ func getImages(vals chartutil.Values) ([]*types.TrackedImage, error) {
}
func getPlanValues(newVersion *types.Version, ref *image.Reference, imageDetails *ImageDetails) (path, value string) {
// vals := make(map[string]string)
// if tag is not supplied, then user specified full image name
if imageDetails.TagPath == "" {
return imageDetails.RepositoryPath, getUpdatedImage(ref, newVersion.String())
@ -103,4 +102,4 @@ func parseImage(vals chartutil.Values, details *ImageDetails) (*image.Reference,
}
return image.Parse(imageName + ":" + imageTag)
}
}

File diff suppressed because it is too large Load Diff

View File

@ -15,17 +15,16 @@ import (
"github.com/keel-hq/keel/extension/notification"
"sigs.k8s.io/yaml"
log "github.com/sirupsen/logrus"
"sigs.k8s.io/yaml"
"helm.sh/helm/v3/pkg/strvals"
_ "helm.sh/helm/v3/pkg/action"
_ "helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/chartutil"
hapi_chart "helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
)
var helm3VersionedUpdatesCounter = prometheus.NewCounterVec(
@ -381,11 +380,11 @@ func (p *Provider) applyPlans(plans []*UpdatePlan) error {
func updateHelmRelease(implementer Implementer, releaseName string, chart *hapi_chart.Chart, overrideValues map[string]string, namespace string, opts ...bool) error {
// set reuse values to false if currentRelease.config is nil
emptyConfig := false
if len(opts) == 1 && opts[0] {
emptyConfig = opts[0]
}
// set reuse values to false if currentRelease.config is nil
emptyConfig := false
if len(opts) == 1 && opts[0] {
emptyConfig = opts[0]
}
resp, err := implementer.UpdateReleaseFromChart(releaseName, chart, overrideValues, namespace, emptyConfig)
if err != nil {
@ -393,8 +392,8 @@ func updateHelmRelease(implementer Implementer, releaseName string, chart *hapi_
}
log.WithFields(log.Fields{
"version": resp.Version,
"release": releaseName,
"version": resp.Version,
"release": releaseName,
"overrideValues": overrideValues,
}).Info("provider.helm3: release updated")
return nil

File diff suppressed because it is too large Load Diff

View File

@ -1,120 +1,110 @@
package helm3
import (
"os"
"strings"
"os"
"strings"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart"
log "github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/release"
// "helm.sh/helm/v3/pkg/cli"
// "helm.sh/helm/v3/pkg/cli"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
// to do:
// * update to latest chart package
// * udpate the paramateres for the function
// * update to latest chart package
// * udpate the paramateres for the function
const DefaultUpdateTimeout = 300
// Implementer - generic helm implementer used to abstract actual implementation
type Implementer interface {
// ListReleases(opts ...helm.ReleaseListOption) ([]*release.Release, error)
ListReleases() ([]*release.Release, error)
ListReleases() ([]*release.Release, error)
UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, namespace string, opts ...bool) (*release.Release, error)
}
// Helm3Implementer - actual helm3 implementer
type Helm3Implementer struct {
// actionConfig *action.Configuration
HelmDriver string
KubeContext string
KubeToken string
KubeAPIServer string
HelmDriver string
KubeContext string
KubeToken string
KubeAPIServer string
}
// NewHelm3Implementer - get new helm implementer
func NewHelm3Implementer() *Helm3Implementer {
// settings := cli.New()
// actionConfig := &action.Configuration{}
// // You can pass an empty string instead of settings.Namespace() to list
// // all namespaces
// if err := actionConfig.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), log.Printf); err != nil {
// log.Printf("%+v", err)
// os.Exit(1)
// }
return &Helm3Implementer{
HelmDriver: os.Getenv("HELM_DRIVER"),
KubeContext: os.Getenv("HELM_KUBECONTEXT"),
KubeToken: os.Getenv("HELM_KUBETOKEN"),
KubeAPIServer: os.Getenv("HELM_KUBEAPISERVER"),
}
return &Helm3Implementer{
HelmDriver: os.Getenv("HELM_DRIVER"),
KubeContext: os.Getenv("HELM_KUBECONTEXT"),
KubeToken: os.Getenv("HELM_KUBETOKEN"),
KubeAPIServer: os.Getenv("HELM_KUBEAPISERVER"),
}
}
// ListReleases - list available releases
func (i *Helm3Implementer) ListReleases() ([]*release.Release, error) {
actionConfig := i.generateConfig("")
client := action.NewList(actionConfig)
results, err := client.Run()
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Fatal("helm3: failed to list release")
return []*release.Release{}, err
}
return results, nil
actionConfig := i.generateConfig("")
client := action.NewList(actionConfig)
results, err := client.Run()
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Fatal("helm3: failed to list release")
return []*release.Release{}, err
}
return results, nil
}
// UpdateReleaseFromChart - update release from chart
// func (i *Helm3Implementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string) (*release.Release, error) {
func (i *Helm3Implementer) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, vals map[string]string, namespace string, opts ...bool) (*release.Release, error) {
actionConfig := i.generateConfig(namespace)
client := action.NewUpgrade(actionConfig)
client.Namespace = namespace
actionConfig := i.generateConfig(namespace)
client := action.NewUpgrade(actionConfig)
client.Namespace = namespace
client.Force = true
client.Timeout = DefaultUpdateTimeout;
client.Timeout = DefaultUpdateTimeout
client.ReuseValues = true
// set reuse values to false if currentRelease.config is nil (temp fix for bug in chartutil.coalesce v3.1.2)
if len(opts) == 1 && opts[0] {
client.ReuseValues = false
}
// set reuse values to false if currentRelease.config is nil (temp fix for bug in chartutil.coalesce v3.1.2)
if len(opts) == 1 && opts[0] {
client.ReuseValues = false
}
convertedVals := convertToInterface(vals)
convertedVals := convertToInterface(vals)
// returns the new release
results, err := client.Run(rlsName, chart, convertedVals)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Fatal("helm3: failed to update release from chart")
return nil, err
}
return results, err
// returns the new release
results, err := client.Run(rlsName, chart, convertedVals)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Fatal("helm3: failed to update release from chart")
return nil, err
}
return results, err
}
func (i *Helm3Implementer) generateConfig(namespace string) (*action.Configuration) {
// settings := cli.New()
config := &genericclioptions.ConfigFlags{
Namespace: &namespace,
Context: &i.KubeContext,
BearerToken: &i.KubeToken,
APIServer: &i.KubeAPIServer,
}
func (i *Helm3Implementer) generateConfig(namespace string) *action.Configuration {
// settings := cli.New()
config := &genericclioptions.ConfigFlags{
Namespace: &namespace,
Context: &i.KubeContext,
BearerToken: &i.KubeToken,
APIServer: &i.KubeAPIServer,
}
actionConfig := &action.Configuration{}
actionConfig := &action.Configuration{}
if err := actionConfig.Init(config, namespace, i.HelmDriver, log.Printf); err != nil {
log.Printf("%+v", err)
os.Exit(1)
}
if err := actionConfig.Init(config, namespace, i.HelmDriver, log.Printf); err != nil {
log.Printf("%+v", err)
os.Exit(1)
}
return actionConfig
return actionConfig
}
// convert map[string]string to map[string]interface
@ -122,17 +112,17 @@ func (i *Helm3Implementer) generateConfig(namespace string) (*action.Configurati
// map[string]string{"image.tag": "0.1.0"}
// to:
// map[string]interface{"image": map[string]interface{"tag": "0.1.0"}}
func convertToInterface(values map[string]string) (map[string]interface{}) {
converted := make(map[string]interface{})
for key, value := range values {
keys := strings.SplitN(key, ".", 2)
if len(keys) == 1 {
converted[key] = value
} else if len(keys) == 2 {
converted[keys[0]] = convertToInterface(map[string]string{
keys[1]: value,
})
}
}
return converted
}
func convertToInterface(values map[string]string) map[string]interface{} {
converted := make(map[string]interface{})
for key, value := range values {
keys := strings.SplitN(key, ".", 2)
if len(keys) == 1 {
converted[key] = value
} else if len(keys) == 2 {
converted[keys[0]] = convertToInterface(map[string]string{
keys[1]: value,
})
}
}
return converted
}

View File

@ -17,4 +17,4 @@ func TestImplementerList(t *testing.T) {
t.Errorf("why no releases? ")
}
}
}

View File

@ -5,7 +5,6 @@ import (
"github.com/keel-hq/keel/types"
"github.com/keel-hq/keel/util/image"
// hapi_chart "k8s.io/helm/pkg/proto/hapi/chart"
hapi_chart "helm.sh/helm/v3/pkg/chart"
log "github.com/sirupsen/logrus"
@ -14,10 +13,10 @@ import (
func checkRelease(repo *types.Repository, namespace, name string, chart *hapi_chart.Chart, config map[string]interface{}) (plan *UpdatePlan, shouldUpdateRelease bool, err error) {
plan = &UpdatePlan{
Chart: chart,
Namespace: namespace,
Name: name,
Values: make(map[string]string),
Chart: chart,
Namespace: namespace,
Name: name,
Values: make(map[string]string),
EmptyConfig: config == nil,
}
@ -97,15 +96,6 @@ func checkRelease(repo *types.Repository, namespace, name string, chart *hapi_ch
continue
}
// if keelCfg.MatchTag && imageRef.Tag() != eventRepoRef.Tag() {
// log.WithFields(log.Fields{
// "parsed_image_name": imageRef.Remote(),
// "target_image_name": repo.Name,
// "policy": keelCfg.Policy.String(),
// }).Info("provider.helm3: match tag set but tags do not match, ignoring")
// continue
// }
if imageDetails.DigestPath != "" {
plan.Values[imageDetails.DigestPath] = repo.Digest
log.WithFields(log.Fields{

View File

@ -7,11 +7,10 @@ import (
"github.com/keel-hq/keel/internal/policy"
"github.com/keel-hq/keel/types"
"helm.sh/helm/v3/pkg/chartutil"
hapi_chart "helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
)
func Test_checkUnversionedRelease(t *testing.T) {
chartValuesPolicyForce := `
name: al Rashid
@ -84,17 +83,17 @@ keel:
helloWorldChart := &hapi_chart.Chart{
// Values: &hapi_chart.Config{Raw: chartValuesPolicyForce},
Values: chartValuesPolicyForceVal,
Values: chartValuesPolicyForceVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldChartPolicyMajor := &hapi_chart.Chart{
Values: chartValuesPolicyMajorVal,
Values: chartValuesPolicyMajorVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldChartPolicyMajorReleaseNotes := &hapi_chart.Chart{
Values: chartValuesPolicyForceReleaseNotesVal,
Values: chartValuesPolicyForceReleaseNotesVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
@ -119,7 +118,7 @@ keel:
namespace: "default",
name: "release-1",
chart: helloWorldChart,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{
Namespace: "default",
@ -133,7 +132,7 @@ keel:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{
{
RepositoryPath: "image.repository",
TagPath: "image.tag",
},
@ -151,7 +150,7 @@ keel:
namespace: "default",
name: "release-1",
chart: helloWorldChartPolicyMajorReleaseNotes,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{
Namespace: "default",
@ -166,7 +165,7 @@ keel:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{
{
RepositoryPath: "image.repository",
TagPath: "image.tag",
ReleaseNotes: "https://github.com/keel-hq/keel/releases",
@ -185,7 +184,7 @@ keel:
namespace: "default",
name: "release-1",
chart: helloWorldChartPolicyMajor,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{
Namespace: "default",
@ -314,25 +313,25 @@ image:
}
helloWorldChart := &hapi_chart.Chart{
Values: chartValuesAVal,
Values: chartValuesAVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNonSemverChart := &hapi_chart.Chart{
Values: chartValuesBVal,
Values: chartValuesBVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNonSemverNoForceChart := &hapi_chart.Chart{
Values: chartValuesNonSemverNoForceVal,
Values: chartValuesNonSemverNoForceVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNoTagChart := &hapi_chart.Chart{
Values: chartValuesNoTagVal,
Values: chartValuesNoTagVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
helloWorldNoKeelCfg := &hapi_chart.Chart{
Values: chartValuesNoKeelCfgVal,
Values: chartValuesNoKeelCfgVal,
Metadata: &hapi_chart.Metadata{Name: "app-x"},
}
@ -341,7 +340,7 @@ image:
namespace string
name string
chart *hapi_chart.Chart
config map[string]interface {}
config map[string]interface{}
}
tests := []struct {
name string
@ -358,7 +357,7 @@ image:
namespace: "default",
name: "release-1",
chart: helloWorldChart,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{
Namespace: "default",
@ -372,7 +371,7 @@ image:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag"},
{RepositoryPath: "image.repository", TagPath: "image.tag"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeAll, true),
},
@ -387,7 +386,7 @@ image:
namespace: "default",
name: "release-1",
chart: helloWorldChart,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{Namespace: "default", Name: "release-1", Chart: helloWorldChart, Values: map[string]string{}},
wantShouldUpdateRelease: false,
@ -401,7 +400,7 @@ image:
namespace: "default",
name: "release-1",
chart: helloWorldChart,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{Namespace: "default", Name: "release-1", Chart: helloWorldChart, Values: map[string]string{}},
wantShouldUpdateRelease: false,
@ -415,7 +414,7 @@ image:
namespace: "default",
name: "release-1",
chart: helloWorldNonSemverChart,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{
Namespace: "default",
@ -429,7 +428,7 @@ image:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository", TagPath: "image.tag"},
{RepositoryPath: "image.repository", TagPath: "image.tag"},
},
Plc: policy.NewForcePolicy(false),
},
@ -445,7 +444,7 @@ image:
namespace: "default",
name: "release-1",
chart: helloWorldNonSemverNoForceChart,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{Namespace: "default", Name: "release-1", Chart: helloWorldNonSemverNoForceChart, Values: map[string]string{}},
wantShouldUpdateRelease: false,
@ -459,7 +458,7 @@ image:
namespace: "default",
name: "release-1-no-tag",
chart: helloWorldNoTagChart,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{
Namespace: "default",
@ -473,7 +472,7 @@ image:
MatchPreRelease: true,
Trigger: types.TriggerTypePoll,
Images: []ImageDetails{
ImageDetails{RepositoryPath: "image.repository"},
{RepositoryPath: "image.repository"},
},
Plc: policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, true),
},
@ -489,7 +488,7 @@ image:
namespace: "default",
name: "release-1-no-tag",
chart: helloWorldNoKeelCfg,
config: make(map[string]interface {}),
config: make(map[string]interface{}),
},
wantPlan: &UpdatePlan{Namespace: "default", Name: "release-1-no-tag", Chart: helloWorldNoKeelCfg, Values: map[string]string{}},
wantShouldUpdateRelease: false,

View File

@ -16,7 +16,7 @@ func TestCheckRequestedApproval(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -37,7 +37,7 @@ func TestCheckRequestedApproval(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -88,7 +88,7 @@ func TestCheckRequestedApprovalAnnotation(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -113,7 +113,7 @@ func TestCheckRequestedApprovalAnnotation(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -171,7 +171,7 @@ func TestApprovedCheck(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -192,7 +192,7 @@ func TestApprovedCheck(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -252,7 +252,7 @@ func TestApprovalsCleanup(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -273,7 +273,7 @@ func TestApprovalsCleanup(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},

View File

@ -141,7 +141,7 @@ func TestGetNamespaces(t *testing.T) {
fi := &fakeImplementer{
namespaces: &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -203,7 +203,7 @@ func TestGetImpacted(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -224,7 +224,7 @@ func TestGetImpacted(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -244,7 +244,7 @@ func TestGetImpacted(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -300,7 +300,7 @@ func TestGetImpactedPolicyAnnotations(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -322,7 +322,7 @@ func TestGetImpactedPolicyAnnotations(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -342,7 +342,7 @@ func TestGetImpactedPolicyAnnotations(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -403,7 +403,7 @@ func TestPrereleaseGetImpactedA(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -424,7 +424,7 @@ func TestPrereleaseGetImpactedA(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1-staging",
},
},
@ -444,7 +444,7 @@ func TestPrereleaseGetImpactedA(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -495,7 +495,7 @@ func TestPrereleaseGetImpactedB(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -516,7 +516,7 @@ func TestPrereleaseGetImpactedB(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1-staging",
},
},
@ -536,7 +536,7 @@ func TestPrereleaseGetImpactedB(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -582,7 +582,7 @@ func TestProcessEvent(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -608,7 +608,7 @@ func TestProcessEvent(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -634,7 +634,7 @@ func TestProcessEvent(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/bye-world:1.1.1",
},
},
@ -665,7 +665,7 @@ func TestProcessEvent(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/bye-world:1.1.1",
},
},
@ -710,7 +710,7 @@ func TestProcessEventBuildNumber(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -731,7 +731,7 @@ func TestProcessEventBuildNumber(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:10",
},
},
@ -773,7 +773,7 @@ func TestEventSent(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -794,7 +794,7 @@ func TestEventSent(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:10.0.0",
},
},
@ -841,7 +841,7 @@ func TestEventSentWithReleaseNotes(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -862,7 +862,7 @@ func TestEventSentWithReleaseNotes(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:10.0.0",
},
},
@ -914,7 +914,7 @@ func TestGetImpactedTwoContainersInSameDeployment(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -935,10 +935,10 @@ func TestGetImpactedTwoContainersInSameDeployment(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
v1.Container{
{
Image: "gcr.io/v2-namespace/greetings-world:1.1.1",
},
},
@ -958,7 +958,7 @@ func TestGetImpactedTwoContainersInSameDeployment(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -1015,7 +1015,7 @@ func TestGetImpactedTwoSameContainersInSameDeployment(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -1036,10 +1036,10 @@ func TestGetImpactedTwoSameContainersInSameDeployment(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -1060,7 +1060,7 @@ func TestGetImpactedTwoSameContainersInSameDeployment(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -1117,7 +1117,7 @@ func TestGetImpactedUntaggedImage(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -1138,7 +1138,7 @@ func TestGetImpactedUntaggedImage(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/foo-world",
},
},
@ -1159,7 +1159,7 @@ func TestGetImpactedUntaggedImage(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -1216,7 +1216,7 @@ func TestGetImpactedUntaggedOneImage(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -1237,7 +1237,7 @@ func TestGetImpactedUntaggedOneImage(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world",
},
},
@ -1258,7 +1258,7 @@ func TestGetImpactedUntaggedOneImage(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -1316,7 +1316,7 @@ func TestTrackedImages(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -1336,12 +1336,12 @@ func TestTrackedImages(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1",
},
},
ImagePullSecrets: []v1.LocalObjectReference{
v1.LocalObjectReference{
{
Name: "very-secret",
},
},
@ -1380,7 +1380,7 @@ func TestTrackedImagesWithSecrets(t *testing.T) {
fp := &fakeImplementer{}
fp.namespaces = &v1.NamespaceList{
Items: []v1.Namespace{
v1.Namespace{
{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{Name: "xxxx"},
v1.NamespaceSpec{},
@ -1403,12 +1403,12 @@ func TestTrackedImagesWithSecrets(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1",
},
},
ImagePullSecrets: []v1.LocalObjectReference{
v1.LocalObjectReference{
{
Name: "very-secret",
},
},

View File

@ -65,7 +65,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world",
},
},
@ -93,7 +93,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:latest",
},
},
@ -125,7 +125,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/goodbye-world:earliest",
},
},
@ -163,7 +163,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:alpha",
},
},
@ -201,7 +201,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "karolisr/keel:latest",
},
},
@ -229,7 +229,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "karolisr/keel:0.2.0",
},
},
@ -266,7 +266,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "karolisr/keel:master",
},
},
@ -296,7 +296,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "karolisr/keel:master",
},
},
@ -336,7 +336,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "karolisr/keel:latest-staging",
},
},
@ -366,7 +366,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "karolisr/keel:latest-staging",
},
},
@ -406,7 +406,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "eu.gcr.io/karolisr/keel:latest-staging",
},
},
@ -437,7 +437,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "eu.gcr.io/karolisr/keel:latest-staging",
},
},
@ -471,7 +471,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "karolisr/keel:latest-acceptance",
},
},
@ -511,7 +511,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "eu.gcr.io/karolisr/keel:latest-staging",
},
},
@ -542,7 +542,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "eu.gcr.io/karolisr/keel:latest-staging",
},
},
@ -581,7 +581,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "eu.gcr.io/karolisr/keel:release-1",
},
},
@ -612,7 +612,7 @@ func TestProvider_checkForUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "eu.gcr.io/karolisr/keel:release-2",
},
},
@ -693,7 +693,7 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -721,7 +721,7 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.2",
},
},
@ -759,7 +759,7 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-prerelease:v1.1.1",
},
},
@ -796,7 +796,7 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-prerelease:v1.1.1-staging",
},
},
@ -828,7 +828,7 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
},
@ -868,10 +868,10 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.1",
},
v1.Container{
{
Image: "yo-world:1.1.1",
},
},
@ -899,10 +899,10 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.2",
},
v1.Container{
{
Image: "yo-world:1.1.1",
},
},
@ -939,10 +939,10 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:latest",
},
v1.Container{
{
Image: "yo-world:1.1.1",
},
},
@ -970,10 +970,10 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.2",
},
v1.Container{
{
Image: "yo-world:1.1.1",
},
},
@ -1013,10 +1013,10 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.2",
},
v1.Container{
{
Image: "yo-world:1.1.1",
},
},
@ -1047,10 +1047,10 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.2",
},
v1.Container{
{
Image: "yo-world:1.1.1",
},
},
@ -1090,10 +1090,10 @@ func TestProvider_checkForUpdateSemver(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Image: "gcr.io/v2-namespace/hello-world:1.1.2",
},
v1.Container{
{
Image: "yo-world:1.1.1",
},
},

View File

@ -305,14 +305,11 @@ var tagsResp = `{
]
}`
func TestGetDockerHubManyTags(t *testing.T) {
client := registry.New("https://quay.io", "", "")
tags, err := client.Tags("coreos/prometheus-operator")
if err != nil {
t.Errorf("error while getting repo: %s", err)
}
fmt.Println(tags)
func TestGetDockerHubManyTags(t *testing.T) {
client := registry.New("https://quay.io", "", "")
tags, err := client.Tags("coreos/prometheus-operator")
if err != nil {
t.Errorf("error while getting repo: %s", err)
}
fmt.Println(tags)
}

View File

@ -35,7 +35,7 @@ func TestGetSecret(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailableSecret: map[string]*v1.Secret{
"myregistrysecret": &v1.Secret{
"myregistrysecret": {
Data: map[string][]byte{
dockerConfigKey: []byte(secretDataPayload),
},
@ -71,7 +71,7 @@ func TestGetDockerConfigJSONSecret(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailableSecret: map[string]*v1.Secret{
"myregistrysecret": &v1.Secret{
"myregistrysecret": {
Data: map[string][]byte{
dockerConfigJSONKey: []byte(secretDockerConfigJSONPayload),
},
@ -106,7 +106,7 @@ func TestGetDockerConfigJSONSecretUsernmePassword(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailableSecret: map[string]*v1.Secret{
"myregistrysecret": &v1.Secret{
"myregistrysecret": {
Data: map[string][]byte{
dockerConfigJSONKey: []byte(secretDockerConfigJSONPayloadWithUsernamePassword),
},
@ -142,7 +142,7 @@ func TestGetFromDefaultCredentials(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailableSecret: map[string]*v1.Secret{
"myregistrysecret": &v1.Secret{
"myregistrysecret": {
Data: map[string][]byte{
dockerConfigJSONKey: []byte(secretDockerConfigJSONPayloadWithUsernamePassword),
},
@ -215,9 +215,9 @@ func TestLookupHelmSecret(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailablePods: &v1.PodList{
Items: []v1.Pod{
v1.Pod{
{
Spec: v1.PodSpec{ImagePullSecrets: []v1.LocalObjectReference{
v1.LocalObjectReference{
{
Name: "very-secret",
},
},
@ -226,7 +226,7 @@ func TestLookupHelmSecret(t *testing.T) {
},
},
AvailableSecret: map[string]*v1.Secret{
"myregistrysecret": &v1.Secret{
"myregistrysecret": {
Data: map[string][]byte{
dockerConfigKey: []byte(fmt.Sprintf(secretDataPayloadEncoded, mustEncode("user-y:pass-y"))),
},
@ -263,9 +263,9 @@ func TestLookupHelmEncodedSecret(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailablePods: &v1.PodList{
Items: []v1.Pod{
v1.Pod{
{
Spec: v1.PodSpec{ImagePullSecrets: []v1.LocalObjectReference{
v1.LocalObjectReference{
{
Name: "very-secret",
},
},
@ -274,7 +274,7 @@ func TestLookupHelmEncodedSecret(t *testing.T) {
},
},
AvailableSecret: map[string]*v1.Secret{
"myregistrysecret": &v1.Secret{
"myregistrysecret": {
Data: map[string][]byte{
dockerConfigKey: []byte(secretDataPayload),
},
@ -311,10 +311,10 @@ func TestGetDirectHelmSecret(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailablePods: &v1.PodList{
Items: []v1.Pod{
v1.Pod{
{
Spec: v1.PodSpec{
ImagePullSecrets: []v1.LocalObjectReference{
v1.LocalObjectReference{
{
Name: "very-secret-dont-look",
},
},
@ -323,13 +323,13 @@ func TestGetDirectHelmSecret(t *testing.T) {
},
},
AvailableSecret: map[string]*v1.Secret{
"myregistrysecret": &v1.Secret{
"myregistrysecret": {
Data: map[string][]byte{
dockerConfigKey: []byte(secretDataPayload2),
},
Type: v1.SecretTypeDockercfg,
},
"very-secret-dont-look": &v1.Secret{
"very-secret-dont-look": {
Data: map[string][]byte{
dockerConfigKey: []byte(secretDataPayload),
},
@ -367,9 +367,9 @@ func TestLookupHelmNoSecretsFound(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailablePods: &v1.PodList{
Items: []v1.Pod{
v1.Pod{
{
Spec: v1.PodSpec{ImagePullSecrets: []v1.LocalObjectReference{
v1.LocalObjectReference{
{
Name: "very-secret",
},
},
@ -411,9 +411,9 @@ func TestLookupWithPortedRegistry(t *testing.T) {
impl := &testutil.FakeK8sImplementer{
AvailablePods: &v1.PodList{
Items: []v1.Pod{
v1.Pod{
{
Spec: v1.PodSpec{ImagePullSecrets: []v1.LocalObjectReference{
v1.LocalObjectReference{
{
Name: "example.com",
},
},
@ -422,7 +422,7 @@ func TestLookupWithPortedRegistry(t *testing.T) {
},
},
AvailableSecret: map[string]*v1.Secret{
"example.com": &v1.Secret{
"example.com": {
Data: map[string][]byte{
dockerConfigKey: []byte(secretDataPayloadWithPort),
},

View File

@ -80,7 +80,7 @@ func TestPollingSemverUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Name: "wd-1",
Image: "keelhq/push-workflow-example:0.1.0-dev",
},
@ -140,7 +140,7 @@ func TestPollingSemverUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Name: "wd-1",
Image: "keelhq/push-workflow-example:0.1.0",
},
@ -197,7 +197,7 @@ func TestPollingSemverUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Name: "wd-1",
Image: "keelhq/push-workflow-example:0.3.0-alpha",
},
@ -335,7 +335,7 @@ func TestPollingPrivateRegistry(t *testing.T) {
},
},
Containers: []v1.Container{
v1.Container{
{
ImagePullPolicy: v1.PullAlways,
Name: "wd-1",
Image: "karolisr/demo-webhook:0.0.1",
@ -447,7 +447,7 @@ func TestPollingPrivateRegistry(t *testing.T) {
},
},
Containers: []v1.Container{
v1.Container{
{
ImagePullPolicy: v1.PullAlways,
Name: "wd-1",
Image: "registry.gitlab.com/karolisr/keel:0.1.0",

View File

@ -101,7 +101,7 @@ func TestWebhooksSemverUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Name: "wd-1",
Image: "karolisr/webhook-demo:0.0.14",
},
@ -205,7 +205,7 @@ func TestWebhookHighIntegerUpdate(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Name: "wd-1",
Image: "karolisr/webhook-demo:0.0.14",
},
@ -339,7 +339,7 @@ func TestApprovals(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Name: "wd-1",
Image: "karolisr/webhook-demo:0.0.14",
},
@ -480,7 +480,7 @@ func TestApprovalsWithAuthentication(t *testing.T) {
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
{
Name: "wd-1",
Image: "karolisr/webhook-demo:0.0.14",
},

View File

@ -55,14 +55,14 @@ func TestCheckDeployment(t *testing.T) {
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: imgA,
Trigger: types.TriggerTypePoll,
Provider: "fp",
PollSchedule: types.KeelPollDefaultSchedule,
},
&types.TrackedImage{
{
Trigger: types.TriggerTypePoll,
Image: imgB,
Provider: "fp",
@ -144,7 +144,7 @@ func TestCheckECRDeployment(t *testing.T) {
imgA, _ := image.Parse("528670773427.dkr.ecr.us-east-2.amazonaws.com/webhook-demo:master")
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: imgA,
Trigger: types.TriggerTypePoll,
Provider: "fp",

View File

@ -23,7 +23,7 @@ func TestWatchMultipleTagsWithSemver(t *testing.T) {
imgA, _ := image.Parse("gcr.io/v2-namespace/hello-world:1.1.1")
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: imgA,
Trigger: types.TriggerTypePoll,
Provider: "fp",
@ -212,7 +212,7 @@ func TestWatchMultipleTagsWithCredentialsHelper(t *testing.T) {
imgA, _ := image.Parse("gcr.io/v2-namespace/hello-world:1.1.1")
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: imgA,
Trigger: types.TriggerTypePoll,
Provider: "fp",

View File

@ -177,7 +177,7 @@ func TestWatchAllTagsJob(t *testing.T) {
reference, _ := image.Parse("foo/bar:1.1.0")
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: reference,
Policy: policy.NewSemverPolicy(policy.SemverPolicyTypeAll, true),
},
@ -221,7 +221,7 @@ func TestWatchAllTagsJobCurrentLatest(t *testing.T) {
reference, _ := image.Parse("foo/bar:latest")
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: reference,
Policy: policy.NewForcePolicy(true),
},
@ -264,7 +264,7 @@ func TestWatchMultipleTags(t *testing.T) {
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: imgA,
Trigger: types.TriggerTypePoll,
Provider: "fp",
@ -273,7 +273,7 @@ func TestWatchMultipleTags(t *testing.T) {
Policy: policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, true),
},
&types.TrackedImage{
{
Trigger: types.TriggerTypePoll,
Image: imgB,
Provider: "fp",
@ -281,7 +281,7 @@ func TestWatchMultipleTags(t *testing.T) {
Policy: policy.NewSemverPolicy(policy.SemverPolicyTypeMajor, true),
},
&types.TrackedImage{
{
Trigger: types.TriggerTypePoll,
Image: imgC,
Provider: "fp",
@ -289,7 +289,7 @@ func TestWatchMultipleTags(t *testing.T) {
Policy: policy.NewForcePolicy(true),
},
&types.TrackedImage{
{
Trigger: types.TriggerTypePoll,
Image: imgD,
Provider: "fp",
@ -422,7 +422,7 @@ func TestWatchTagJobLatestECR(t *testing.T) {
imgA, _ := image.Parse("528670773427.dkr.ecr.us-east-2.amazonaws.com/webhook-demo:master")
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: imgA,
Trigger: types.TriggerTypePoll,
Provider: "fp",

View File

@ -82,7 +82,7 @@ func TestCheckDeployment(t *testing.T) {
img, _ := image.Parse("gcr.io/v2-namespace/hello-world:1.1")
fp := &fakeProvider{
images: []*types.TrackedImage{
&types.TrackedImage{
{
Image: img,
Provider: "fp",
},

View File

@ -13,4 +13,4 @@ func ValidateID(id string) error {
return fmt.Errorf("image ID '%s' is invalid ", id)
}
return nil
}
}