Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from keptn-contrib/master
Browse files Browse the repository at this point in the history
Fix Service Account, send release event
  • Loading branch information
agrimmer authored Aug 3, 2020
2 parents 0995e5f + ee859ea commit 6858e19
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 33 deletions.
59 changes: 59 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import (
"context"
"fmt"
"log"
"net/url"
"os"
"strings"
"time"

"github.com/cloudevents/sdk-go/pkg/cloudevents/types"
"github.com/google/uuid"

"github.com/keptn-contrib/argo-service/pkg/lib/argo"

Expand Down Expand Up @@ -77,6 +82,12 @@ func promote(event cloudevents.Event, logger *keptnutils.Logger) error {
return err
}

keptn, err := keptnutils.NewKeptn(&event, keptnutils.KeptnOpts{})
if err != nil {
logger.Info("failed to create keptn handler")
return err
}

// Evaluation has passed if we have result = pass or result = warning
if data.Result == "pass" || data.Result == "warning" {

Expand All @@ -93,6 +104,13 @@ func promote(event cloudevents.Event, logger *keptnutils.Logger) error {
return err
}
logger.Info(output)

return keptn.SendCloudEvent(getCloudEvent(PromoteEventData{
Project: data.Project,
Service: data.Service,
Stage: data.Stage,
Action: "promote",
}, "sh.keptn.event.release.finished", keptn.KeptnContext, event.ID()))
}

} else {
Expand All @@ -109,7 +127,48 @@ func promote(event cloudevents.Event, logger *keptnutils.Logger) error {
return err
}
logger.Info(output)
return keptn.SendCloudEvent(getCloudEvent(PromoteEventData{
Project: data.Project,
Service: data.Service,
Stage: data.Stage,
Action: "aborte",
}, "sh.keptn.event.release.finished", keptn.KeptnContext, event.ID()))
}
}
return nil
}

// ConfigurationChangeEventData represents the data for changing the service configuration
type PromoteEventData struct {
// Project is the name of the project
Project string `json:"project"`
// Service is the name of the new service
Service string `json:"service"`
// Stage is the name of the stage
Stage string `json:"stage"`

Action string `json:action`
}

func getCloudEvent(data interface{}, ceType string, shkeptncontext string, triggeredID string) cloudevents.Event {

source, _ := url.Parse("argo-service")
contentType := "application/json"

extensions := map[string]interface{}{"shkeptncontext": shkeptncontext}
if triggeredID != "" {
extensions["triggeredid"] = triggeredID
}

return cloudevents.Event{
Context: cloudevents.EventContextV02{
ID: uuid.New().String(),
Time: &types.Timestamp{Time: time.Now()},
Type: ceType,
Source: types.URLRef{URL: *source},
ContentType: &contentType,
Extensions: extensions,
}.AsV02(),
Data: data,
}
}
103 changes: 70 additions & 33 deletions deploy/service.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
---
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: keptn-argo-service
namespace: keptn
labels:
"app": "keptn"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: keptn-argo-service-rollouts
labels:
"app": "keptn"
rules:
- apiGroups:
- "argoproj.io"
resources:
- rollouts
verbs:
- "*"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: keptn-argo-service-rollouts
labels:
"app": "keptn"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: keptn-argo-service-rollouts
subjects:
- kind: ServiceAccount
name: keptn-argo-service
namespace: keptn
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -14,37 +51,37 @@ spec:
labels:
run: argo-service
spec:
serviceAccountName: keptn-default
serviceAccountName: keptn-argo-service
containers:
- name: argo-service
image: keptncontrib/argo-service:0.1.1
ports:
- containerPort: 8080
resources:
requests:
memory: "32Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "500m"
- name: distributor
image: keptn/distributor:0.7.0
ports:
- containerPort: 8080
resources:
requests:
memory: "32Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "500m"
env:
- name: PUBSUB_URL
value: 'nats://keptn-nats-cluster'
- name: PUBSUB_TOPIC
value: 'sh.keptn.events.evaluation-done'
- name: PUBSUB_RECIPIENT
value: '127.0.0.1'
- name: argo-service
image: keptncontrib/argo-service:0.1.1
ports:
- containerPort: 8080
resources:
requests:
memory: "32Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "500m"
- name: distributor
image: keptn/distributor:0.7.0
ports:
- containerPort: 8080
resources:
requests:
memory: "32Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "500m"
env:
- name: PUBSUB_URL
value: 'nats://keptn-nats-cluster'
- name: PUBSUB_TOPIC
value: 'sh.keptn.events.evaluation-done'
- name: PUBSUB_RECIPIENT
value: '127.0.0.1'
---
apiVersion: v1
kind: Service
Expand All @@ -55,7 +92,7 @@ metadata:
run: argo-service
spec:
ports:
- port: 8080
protocol: TCP
- port: 8080
protocol: TCP
selector:
run: argo-service

0 comments on commit 6858e19

Please sign in to comment.