diff --git a/hack/deployment.sample.yml b/hack/deployment.sample.yml index 9e334f23..4133fb61 100644 --- a/hack/deployment.sample.yml +++ b/hack/deployment.sample.yml @@ -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 @@ -33,6 +33,4 @@ spec: path: /healthz port: 9300 initialDelaySeconds: 30 - timeoutSeconds: 10 - securityContext: - privileged: true + timeoutSeconds: 10 diff --git a/provider/kubernetes/kubernetes.go b/provider/kubernetes/kubernetes.go index a012f0fe..b89b7e82 100644 --- a/provider/kubernetes/kubernetes.go +++ b/provider/kubernetes/kubernetes.go @@ -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 { diff --git a/provider/kubernetes/kubernetes_test.go b/provider/kubernetes/kubernetes_test.go index fa1c75e6..12f569ec 100644 --- a/provider/kubernetes/kubernetes_test.go +++ b/provider/kubernetes/kubernetes_test.go @@ -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") + } + +} diff --git a/util/version/version.go b/util/version/version.go index 237115f3..6e9e110b 100644 --- a/util/version/version.go +++ b/util/version/version.go @@ -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]) } diff --git a/util/version/version_test.go b/util/version/version_test.go index 2fe52802..1fcdc5d5 100644 --- a/util/version/version_test.go +++ b/util/version/version_test.go @@ -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"},