-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from rusenask/feature/polling
Feature/polling
- Loading branch information
Showing
981 changed files
with
212,552 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package constants | ||
|
||
// DefaultDockerRegistry - default docker registry | ||
const DefaultDockerRegistry = "https://index.docker.io" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
func addImageToPull(annotations map[string]string, image string) map[string]string { | ||
existing, ok := annotations[forceUpdateImageAnnotation] | ||
if ok { | ||
// check if it's already there | ||
if shouldPullImage(annotations, image) { | ||
// skipping | ||
return annotations | ||
} | ||
|
||
annotations[forceUpdateImageAnnotation] = existing + "," + image | ||
return annotations | ||
} | ||
annotations[forceUpdateImageAnnotation] = image | ||
return annotations | ||
} | ||
|
||
func shouldPullImage(annotations map[string]string, image string) bool { | ||
imagesStr, ok := annotations[forceUpdateImageAnnotation] | ||
if !ok { | ||
return false | ||
} | ||
|
||
images := strings.Split(imagesStr, ",") | ||
for _, img := range images { | ||
if img == image { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_addImageToPull(t *testing.T) { | ||
type args struct { | ||
annotations map[string]string | ||
image string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]string | ||
}{ | ||
{ | ||
name: "empty", | ||
args: args{annotations: make(map[string]string), image: "whatever"}, | ||
want: map[string]string{forceUpdateImageAnnotation: "whatever"}, | ||
}, | ||
{ | ||
name: "not empty", | ||
args: args{annotations: map[string]string{forceUpdateImageAnnotation: "foo"}, image: "bar"}, | ||
want: map[string]string{forceUpdateImageAnnotation: "foo,bar"}, | ||
}, | ||
{ | ||
name: "not empty with same image", | ||
args: args{annotations: map[string]string{forceUpdateImageAnnotation: "foo"}, image: "foo"}, | ||
want: map[string]string{forceUpdateImageAnnotation: "foo"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := addImageToPull(tt.args.annotations, tt.args.image); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("addImageToPull() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_shouldPullImage(t *testing.T) { | ||
type args struct { | ||
annotations map[string]string | ||
image string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "should pull single image", | ||
args: args{annotations: map[string]string{forceUpdateImageAnnotation: "bar"}, image: "bar"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "should pull multiple image", | ||
args: args{annotations: map[string]string{forceUpdateImageAnnotation: "foo,bar,whatever"}, image: "bar"}, | ||
want: true, | ||
}, | ||
{ | ||
name: "should not pull multiple image", | ||
args: args{annotations: map[string]string{forceUpdateImageAnnotation: "foo,bar,whatever"}, image: "alpha"}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := shouldPullImage(tt.args.annotations, tt.args.image); got != tt.want { | ||
t.Errorf("shouldPullImage() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.