commit
bfcf2b58b6
|
@ -11,7 +11,6 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *types.Repository, deployment v1beta1.Deployment) (updated v1beta1.Deployment, shouldUpdateDeployment bool, err error) {
|
||||
func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *types.Repository, deployment v1beta1.Deployment) (updatePlan *UpdatePlan, shouldUpdateDeployment bool, err error) {
|
||||
updatePlan = &UpdatePlan{}
|
||||
|
||||
|
@ -28,6 +27,8 @@ func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *typ
|
|||
"policy": policy,
|
||||
}).Info("provider.kubernetes.checkVersionedDeployment: keel policy found, checking deployment...")
|
||||
|
||||
annotations := deployment.GetAnnotations()
|
||||
|
||||
shouldUpdateDeployment = false
|
||||
|
||||
for idx, c := range deployment.Spec.Template.Spec.Containers {
|
||||
|
@ -61,6 +62,14 @@ func (p *Provider) checkUnversionedDeployment(policy types.PolicyType, repo *typ
|
|||
continue
|
||||
}
|
||||
|
||||
// if poll trigger is used, also checking for matching versions
|
||||
if _, ok := annotations[types.KeelPollScheduleAnnotation]; ok {
|
||||
if repo.Tag != containerImageRef.Tag() {
|
||||
fmt.Printf("tags different, not updating (%s != %s) \n", eventRepoRef.Tag(), containerImageRef.Tag())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// updating image
|
||||
if containerImageRef.Registry() == image.DefaultRegistryHostname {
|
||||
c.Image = fmt.Sprintf("%s:%s", containerImageRef.ShortName(), repo.Tag)
|
||||
|
|
|
@ -121,6 +121,43 @@ func TestProvider_checkUnversionedDeployment(t *testing.T) {
|
|||
wantShouldUpdateDeployment: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "different tag name for poll image",
|
||||
args: args{
|
||||
policy: types.PolicyTypeForce,
|
||||
repo: &types.Repository{Name: "gcr.io/v2-namespace/hello-world", Tag: "master"},
|
||||
deployment: v1beta1.Deployment{
|
||||
meta_v1.TypeMeta{},
|
||||
meta_v1.ObjectMeta{
|
||||
Name: "dep-1",
|
||||
Namespace: "xxxx",
|
||||
Annotations: map[string]string{
|
||||
types.KeelPollScheduleAnnotation: types.KeelPollDefaultSchedule,
|
||||
},
|
||||
Labels: map[string]string{
|
||||
types.KeelPolicyLabel: "all",
|
||||
},
|
||||
},
|
||||
v1beta1.DeploymentSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
v1.Container{
|
||||
Image: "gcr.io/v2-namespace/hello-world:alpha",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
v1beta1.DeploymentStatus{},
|
||||
},
|
||||
},
|
||||
wantUpdatePlan: &UpdatePlan{
|
||||
Deployment: v1beta1.Deployment{},
|
||||
},
|
||||
wantShouldUpdateDeployment: false,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "dockerhub short image name ",
|
||||
args: args{
|
||||
|
@ -176,6 +213,64 @@ func TestProvider_checkUnversionedDeployment(t *testing.T) {
|
|||
wantShouldUpdateDeployment: true,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "poll trigger, same tag",
|
||||
args: args{
|
||||
policy: types.PolicyTypeForce,
|
||||
repo: &types.Repository{Name: "karolisr/keel", Tag: "master"},
|
||||
deployment: v1beta1.Deployment{
|
||||
meta_v1.TypeMeta{},
|
||||
meta_v1.ObjectMeta{
|
||||
Name: "dep-1",
|
||||
Namespace: "xxxx",
|
||||
Annotations: map[string]string{types.KeelPollScheduleAnnotation: types.KeelPollDefaultSchedule},
|
||||
Labels: map[string]string{types.KeelPolicyLabel: "force"},
|
||||
},
|
||||
v1beta1.DeploymentSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
v1.Container{
|
||||
Image: "karolisr/keel:master",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
v1beta1.DeploymentStatus{},
|
||||
},
|
||||
},
|
||||
wantUpdatePlan: &UpdatePlan{
|
||||
Deployment: v1beta1.Deployment{
|
||||
meta_v1.TypeMeta{},
|
||||
meta_v1.ObjectMeta{
|
||||
Name: "dep-1",
|
||||
Namespace: "xxxx",
|
||||
Annotations: map[string]string{
|
||||
types.KeelPollScheduleAnnotation: types.KeelPollDefaultSchedule,
|
||||
forceUpdateImageAnnotation: "karolisr/keel:master",
|
||||
},
|
||||
Labels: map[string]string{types.KeelPolicyLabel: "force"},
|
||||
},
|
||||
v1beta1.DeploymentSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
v1.Container{
|
||||
Image: "karolisr/keel:master",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
v1beta1.DeploymentStatus{},
|
||||
},
|
||||
NewVersion: "master",
|
||||
CurrentVersion: "master",
|
||||
},
|
||||
wantShouldUpdateDeployment: true,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
@ -70,6 +70,12 @@ func (w *RepositoryWatcher) Start(ctx context.Context) {
|
|||
}
|
||||
|
||||
func getImageIdentifier(ref *image.Reference) string {
|
||||
_, err := version.GetVersion(ref.Tag())
|
||||
// if failed to parse version, will need to watch digest
|
||||
if err != nil {
|
||||
return ref.Registry() + "/" + ref.ShortName() + ":" + ref.Tag()
|
||||
}
|
||||
|
||||
return ref.Registry() + "/" + ref.ShortName()
|
||||
}
|
||||
|
||||
|
|
|
@ -206,3 +206,84 @@ func TestWatchAllTagsJobCurrentLatest(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func TestWatchMultipleTags(t *testing.T) {
|
||||
// fake provider listening for events
|
||||
imgA, _ := image.Parse("gcr.io/v2-namespace/hello-world:1.1.1")
|
||||
imgB, _ := image.Parse("gcr.io/v2-namespace/greetings-world:1.1.1")
|
||||
imgC, _ := image.Parse("gcr.io/v2-namespace/greetings-world:alpha")
|
||||
imgD, _ := image.Parse("gcr.io/v2-namespace/greetings-world:master")
|
||||
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",
|
||||
PollSchedule: types.KeelPollDefaultSchedule,
|
||||
},
|
||||
|
||||
&types.TrackedImage{
|
||||
Trigger: types.TriggerTypePoll,
|
||||
Image: imgC,
|
||||
Provider: "fp",
|
||||
PollSchedule: types.KeelPollDefaultSchedule,
|
||||
},
|
||||
|
||||
&types.TrackedImage{
|
||||
Trigger: types.TriggerTypePoll,
|
||||
Image: imgD,
|
||||
Provider: "fp",
|
||||
PollSchedule: types.KeelPollDefaultSchedule,
|
||||
},
|
||||
},
|
||||
}
|
||||
mem := memory.NewMemoryCache(100*time.Millisecond, 100*time.Millisecond, 10*time.Millisecond)
|
||||
am := approvals.New(mem, codecs.DefaultSerializer())
|
||||
providers := provider.New([]provider.Provider{fp}, am)
|
||||
|
||||
// returning some sha
|
||||
frc := &fakeRegistryClient{
|
||||
digestToReturn: "sha256:0604af35299dd37ff23937d115d103532948b568a9dd8197d14c256a8ab8b0bb",
|
||||
tagsToReturn: []string{"5.0.0"},
|
||||
}
|
||||
|
||||
watcher := NewRepositoryWatcher(providers, frc)
|
||||
|
||||
watcher.Watch("gcr.io/v2-namespace/hello-world:1.1.1", "@every 10m", "", "")
|
||||
watcher.Watch("gcr.io/v2-namespace/greetings-world:1.1.1", "@every 10m", "", "")
|
||||
watcher.Watch("gcr.io/v2-namespace/greetings-world:alpha", "@every 10m", "", "")
|
||||
watcher.Watch("gcr.io/v2-namespace/greetings-world:master", "@every 10m", "", "")
|
||||
|
||||
if len(watcher.watched) != 4 {
|
||||
t.Errorf("expected to find watching 4 entries, found: %d", len(watcher.watched))
|
||||
}
|
||||
|
||||
if dig, ok := watcher.watched["gcr.io/v2-namespace/greetings-world:alpha"]; ok != true {
|
||||
t.Errorf("alpha watcher not found")
|
||||
if dig.digest != "sha256:0604af35299dd37ff23937d115d103532948b568a9dd8197d14c256a8ab8b0bb" {
|
||||
t.Errorf("digest not set for alpha")
|
||||
}
|
||||
}
|
||||
|
||||
if dig, ok := watcher.watched["gcr.io/v2-namespace/greetings-world:master"]; ok != true {
|
||||
t.Errorf("alpha watcher not found")
|
||||
if dig.digest != "sha256:0604af35299dd37ff23937d115d103532948b568a9dd8197d14c256a8ab8b0bb" {
|
||||
t.Errorf("digest not set for alpha")
|
||||
}
|
||||
}
|
||||
|
||||
if det, ok := watcher.watched["gcr.io/v2-namespace/greetings-world"]; ok != true {
|
||||
t.Errorf("alpha watcher not found")
|
||||
if det.latest != "5.0.0" {
|
||||
t.Errorf("expected to find a tag set for multiple tags watch job")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue