Skip to content

Commit

Permalink
Merge pull request #19 from rusenask/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rusenask authored Jul 2, 2017
2 parents 2bb80bc + a5f3ab9 commit caddc23
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
6 changes: 2 additions & 4 deletions hack/deployment.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
app: keel
spec:
containers:
- image: karolisr/keel:0.2.1
- image: karolisr/keel:0.2.3
imagePullPolicy: Always
env:
- name: PUBSUB
Expand All @@ -33,6 +33,4 @@ spec:
path: /healthz
port: 9300
initialDelaySeconds: 30
timeoutSeconds: 10
securityContext:
privileged: true
timeoutSeconds: 10
2 changes: 2 additions & 0 deletions provider/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (p *Provider) startInternal() error {
case event := <-p.events:
log.WithFields(log.Fields{
"repository": event.Repository.Name,
"tag": event.Repository.Tag,
"registry": event.Repository.Host,
}).Info("provider.kubernetes: processing event")
_, err := p.processEvent(event)
if err != nil {
Expand Down
93 changes: 93 additions & 0 deletions provider/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,96 @@ func TestGetImpactedTwoSameContainersInSameDeployment(t *testing.T) {
}

}

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{},
v1.NamespaceStatus{},
},
},
}
fp.deploymentList = &v1beta1.DeploymentList{
Items: []v1beta1.Deployment{
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-1",
Namespace: "xxxx",
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",
},
},
},
},
},
v1beta1.DeploymentStatus{},
},
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-2",
Namespace: "xxxx",
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:1.1.1",
},
},
},
},
},
v1beta1.DeploymentStatus{},
},
},
}

provider, err := NewProvider(fp)
if err != nil {
t.Fatalf("failed to get provider: %s", err)
}

// creating "new version" event
repo := &types.Repository{
Name: "gcr.io/v2-namespace/hello-world",
Tag: "1.1.2",
}

deps, err := provider.impactedDeployments(repo)
if err != nil {
t.Errorf("failed to get deployments: %s", err)
}

if len(deps) != 1 {
t.Errorf("expected to find 1 deployment but found %s", len(deps))
}

found := false
for _, c := range deps[0].Spec.Template.Spec.Containers {

containerImageName := versionreg.ReplaceAllString(c.Image, "")

if containerImageName == repo.Name {
found = true
}
}

if !found {
t.Errorf("couldn't find expected deployment in impacted deployment list")
}

}
2 changes: 1 addition & 1 deletion util/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetVersion(version string) (*types.Version, error) {
// GetVersionFromImageName - get version from image name
func GetVersionFromImageName(name string) (*types.Version, error) {
parts := strings.Split(name, ":")
if len(parts) > 0 {
if len(parts) > 1 {
return GetVersion(parts[1])
}

Expand Down
5 changes: 5 additions & 0 deletions util/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func TestGetVersionFromImageName(t *testing.T) {
args: args{name: "karolis/webhook-demo:latest"},
wantErr: true,
},
{
name: "image no tag",
args: args{name: "karolis/webhook-demo"},
wantErr: true,
},
{
name: "image webhookrelay",
args: args{name: "gcr.io/webhookrelay/webhookrelay:0.1.14"},
Expand Down

0 comments on commit caddc23

Please sign in to comment.