Skip to content

Commit

Permalink
Merge pull request #507 from nnt1054/feature/helm3_provider
Browse files Browse the repository at this point in the history
Feature/helm3 provider
  • Loading branch information
rusenask authored Jul 14, 2020
2 parents 614398d + e7f1ecd commit 3198921
Show file tree
Hide file tree
Showing 43 changed files with 3,920 additions and 1,746 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ alpha: image
e2e: install
cd tests && go test

run: install
run:
go install github.com/keel-hq/keel/cmd/keel
keel --no-incluster --ui-dir ui/dist

lint-ui:
Expand Down
1 change: 0 additions & 1 deletion bot/formatter/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,3 @@ func (c *ApprovalContext) Created() string {
c.AddHeader(ApprovalCreatedHeader)
return c.v.CreatedAt.String()
}

2 changes: 1 addition & 1 deletion bot/hipchat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package hipchat
import (
"time"

log "github.com/sirupsen/logrus"
"github.com/daneharrigan/hipchat"
log "github.com/sirupsen/logrus"
)

type XmppImplementer interface {
Expand Down
2 changes: 1 addition & 1 deletion bot/hipchat/hipchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/keel-hq/keel/bot"
"github.com/keel-hq/keel/constants"

log "github.com/sirupsen/logrus"
h "github.com/daneharrigan/hipchat"
log "github.com/sirupsen/logrus"
)

const connectionAttemptsDefault = 5
Expand Down
36 changes: 18 additions & 18 deletions bot/slack/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ func (b *Bot) RequestApproval(req *types.Approval) error {
req.Message,
types.LevelSuccess.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "Approval required!",
Value: req.Message + "\n" + fmt.Sprintf("To vote for change type '%s approve %s' to reject it: '%s reject %s'.", b.name, req.Identifier, b.name, req.Identifier),
Short: false,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", req.VotesReceived, req.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: req.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: req.Identifier,
Short: true,
},
slack.AttachmentField{
{
Title: "Provider",
Value: req.Provider.String(),
Short: true,
Expand All @@ -50,22 +50,22 @@ func (b *Bot) ReplyToApproval(approval *types.Approval) error {
"All approvals received, thanks for voting!",
types.LevelInfo.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "vote received!",
Value: "Waiting for remaining votes.",
Short: false,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", approval.VotesReceived, approval.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: approval.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: approval.Identifier,
Short: true,
Expand All @@ -77,27 +77,27 @@ func (b *Bot) ReplyToApproval(approval *types.Approval) error {
"Change was rejected",
types.LevelWarn.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "change rejected",
Value: "Change was rejected.",
Short: false,
},
slack.AttachmentField{
{
Title: "Status",
Value: approval.Status().String(),
Short: true,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", approval.VotesReceived, approval.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: approval.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: approval.Identifier,
Short: true,
Expand All @@ -109,22 +109,22 @@ func (b *Bot) ReplyToApproval(approval *types.Approval) error {
"All approvals received, thanks for voting!",
types.LevelSuccess.Color(),
[]slack.AttachmentField{
slack.AttachmentField{
{
Title: "update approved!",
Value: "All approvals received, thanks for voting!",
Short: false,
},
slack.AttachmentField{
{
Title: "Votes",
Value: fmt.Sprintf("%d/%d", approval.VotesReceived, approval.VotesRequired),
Short: true,
},
slack.AttachmentField{
{
Title: "Delta",
Value: approval.Delta(),
Short: true,
},
slack.AttachmentField{
{
Title: "Identifier",
Value: approval.Identifier,
Short: true,
Expand Down
2 changes: 1 addition & 1 deletion bot/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (b *Bot) postMessage(title, message, color string, fields []slack.Attachmen
params.IconURL = b.getBotUserIconURL()

attachements := []slack.Attachment{
slack.Attachment{
{
Fallback: message,
Color: color,
Fields: fields,
Expand Down
2 changes: 1 addition & 1 deletion bot/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func TestProcessRejectedReply(t *testing.T) {
}

func TestIsApproval(t *testing.T) {

event := &slack.MessageEvent{
Msg: slack.Msg{
Channel: "approvals",
Expand Down
2 changes: 1 addition & 1 deletion chart/keel/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: keel
description: Open source, tool for automating Kubernetes deployment updates. Keel is stateless, robust and lightweight.
version: 0.8.22
# Note that we use appVersion to get images tag, so make sure this is correct.
appVersion: 0.16.0
appVersion: 0.16.1
keywords:
- kubernetes deployment
- helm release
Expand Down
4 changes: 3 additions & 1 deletion chart/keel/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{{- if .Values.rbac.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
# apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: {{ template "keel.name" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "keel.name" . }}
# name: {{ template "keel.name" . }}
name: cluster-admin
subjects:
- kind: ServiceAccount
name: {{ template "serviceAccount.name" . }}
Expand Down
14 changes: 10 additions & 4 deletions chart/keel/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,33 @@ spec:
{{- if .Values.polling.enabled }}
# Enable polling
- name: POLL
value: "1"
value: "true"
{{- else }}
# Disable polling
- name: POLL
value: "0"
value: "false"
{{- end }}
{{- if .Values.helmProvider.enabled }}
{{- if eq .Values.helmProvider.version "v2" }}
# Enable/disable Helm provider
- name: HELM_PROVIDER
value: "1"
value: "true"
- name: TILLER_NAMESPACE
value: "{{ .Values.helmProvider.tillerNamespace }}"
- name: TILLER_ADDRESS
value: "{{ .Values.helmProvider.tillerAddress }}"
{{- else if eq .Values.helmProvider.version "v3" }}
# Enable/disable Helm provider
- name: HELM3_PROVIDER
value: "true"
{{- end }}
{{- end }}
{{- if .Values.gcr.enabled }}
# Enable GCR with pub/sub support
- name: PROJECT_ID
value: "{{ .Values.gcr.projectId }}"
- name: PUBSUB
value: "1"
value: "true"
{{- if .Values.gcr.clusterName }}
# Customize the cluster name, mainly useful when outside of GKE
- name: CLUSTER_NAME
Expand Down
24 changes: 13 additions & 11 deletions chart/keel/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ polling:
# Helm provider support
helmProvider:
enabled: true
# set to version "v3" for Helm v3
version: "v2"
tillerNamespace: "kube-system"
# optional Tiller address (if portforwarder tunnel doesn't work),
# if you are using default configuration, setting it to
Expand Down Expand Up @@ -126,17 +128,17 @@ secret:
# Keel self-update
# uncomment lines below if you want Keel to automaticly
# self-update to the latest release version
keel:
# keel policy (all/major/minor/patch/force)
policy: patch
# trigger type, defaults to events such as pubsub, webhooks
trigger: poll
# polling schedule
pollSchedule: "@every 3m"
# images to track and update
images:
- repository: image.repository
tag: image.tag
# keel:
# # keel policy (all/major/minor/patch/force)
# policy: patch
# # trigger type, defaults to events such as pubsub, webhooks
# trigger: poll
# # polling schedule
# pollSchedule: "@every 3m"
# # images to track and update
# images:
# - repository: image.repository
# tag: image.tag

# RBAC manifests management
rbac:
Expand Down
27 changes: 24 additions & 3 deletions cmd/keel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"

"github.com/prometheus/client_golang/prometheus"
netContext "golang.org/x/net/context"
kingpin "gopkg.in/alecthomas/kingpin.v2"
kube "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/keel-hq/keel/internal/workgroup"
"github.com/keel-hq/keel/provider"
"github.com/keel-hq/keel/provider/helm"
"github.com/keel-hq/keel/provider/helm3"
"github.com/keel-hq/keel/provider/kubernetes"
"github.com/keel-hq/keel/registry"
"github.com/keel-hq/keel/secrets"
Expand All @@ -58,6 +58,9 @@ import (
_ "github.com/keel-hq/keel/bot/slack"

log "github.com/sirupsen/logrus"

// importing to ensure correct dependencies
_ "helm.sh/helm/v3/pkg/action"
)

// gcloud pubsub related config
Expand All @@ -70,6 +73,7 @@ const (
EnvHelmProvider = "HELM_PROVIDER" // helm provider
EnvHelmTillerAddress = "TILLER_ADDRESS" // helm provider
EnvHelmTillerNamespace = "TILLER_NAMESPACE" // helm provider
EnvHelm3Provider = "HELM3_PROVIDER" // helm3 provider
EnvUIDir = "UI_DIR"

// EnvDefaultDockerRegistryCfg - default registry configuration that can be passed into
Expand Down Expand Up @@ -134,7 +138,7 @@ func main() {
notification.RegisterSender("auditor", auditLogger)

// setting up triggers
ctx, cancel := netContext.WithCancel(context.Background())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

notificationLevel := types.LevelInfo
Expand Down Expand Up @@ -355,6 +359,23 @@ func setupProviders(opts *ProviderOpts) (providers provider.Providers) {
enabledProviders = append(enabledProviders, helmProvider)
}

if os.Getenv(EnvHelm3Provider) == "1" || os.Getenv(EnvHelm3Provider) == "true" {
helm3Implementer := helm3.NewHelm3Implementer()
helm3Provider := helm3.NewProvider(helm3Implementer, opts.sender, opts.approvalsManager)

go func() {
err := helm3Provider.Start()
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Fatal("helm3 provider stopped with an error")
}
}()

enabledProviders = append(enabledProviders, helm3Provider)

}

providers = provider.New(enabledProviders, opts.approvalsManager)

return providers
Expand Down Expand Up @@ -426,7 +447,7 @@ func setupTriggers(ctx context.Context, opts *TriggerOpts) (teardown func()) {
go subManager.Start(ctx)
}

if os.Getenv(EnvTriggerPoll) != "0" {
if os.Getenv(EnvTriggerPoll) != "0" || os.Getenv(EnvTriggerPoll) != "false" {

registryClient := registry.New()
watcher := poll.NewRepositoryWatcher(opts.providers, registryClient)
Expand Down
4 changes: 2 additions & 2 deletions extension/notification/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ func (s *sender) Send(event types.EventNotification) error {
params.IconURL = constants.KeelLogoURL

attachements := []slack.Attachment{
slack.Attachment{
{
Fallback: event.Message,
Color: event.Level.Color(),
Fields: []slack.AttachmentField{
slack.AttachmentField{
{
Title: event.Type.String(),
Value: event.Message,
Short: false,
Expand Down
Loading

0 comments on commit 3198921

Please sign in to comment.