Skip to content

Commit

Permalink
add prometheus to helm chart (#36)
Browse files Browse the repository at this point in the history
* add prometheus to helm chart

Signed-off-by: scott weiss <sdw35@cornell.edu>
* Merge branch 'master' into add-prometheus-to-helmchart

Signed-off-by: scott weiss <sdw35@cornell.edu>
* use defaults in flag parse

Signed-off-by: scott weiss <sdw35@cornell.edu>
* set from env

Signed-off-by: scott weiss <sdw35@cornell.edu>
* fix dependency in makefile

Signed-off-by: scott weiss <sdw35@cornell.edu>
* fix init

Signed-off-by: scott weiss <sdw35@cornell.edu>
* include HELM_HOME in cb file
* Merge branch 'add-prometheus-to-helmchart' of github.com:solo-io/glooshot into add-prometheus-to-helmchart
* revert helm init
  • Loading branch information
ilackarms authored and soloio-bulldozer[bot] committed May 13, 2019
1 parent 2c373db commit f55f1b2
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 21 deletions.
1 change: 1 addition & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,18 @@ HELM_DIR := install/helm/$(SOLO_NAME)
INSTALL_NAMESPACE ?= $(SOLO_NAME)

.PHONY: manifest
manifest: must prepare-helm install/$(SOLO_NAME).yaml update-helm-chart
manifest: prepare-helm init-helm install/$(SOLO_NAME).yaml update-helm-chart

# creates Chart.yaml, values.yaml
.PHONY: prepare-helm
prepare-helm: must
go run install/helm/$(SOLO_NAME)/generate/cmd/generate.go $(IMAGE_TAG) $(CONTAINER_REPO_ORG)

.PHONY: init-helm
init-helm:
helm repo add supergloo https://storage.googleapis.com/supergloo-helm
helm dependency update install/helm/glooshot

.PHONY: update-helm-chart
update-helm-chart: must
mkdir -p $(HELM_SYNC_DIR)/charts
Expand All @@ -133,7 +138,7 @@ update-helm-chart: must

HELMFLAGS := --namespace $(INSTALL_NAMESPACE) --set namespace.create=true

install/$(SOLO_NAME).yaml: prepare-helm
install/$(SOLO_NAME).yaml: prepare-helm init-helm
helm template install/helm/$(SOLO_NAME) $(HELMFLAGS) > $@

.PHONY: render-yaml
Expand Down
4 changes: 4 additions & 0 deletions changelog/v0.0.2/prometheus-helm-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: NEW_FEATURE
description: add prometheus to the helm chart
issueLink: https://github.com/solo-io/glooshot/issues/37
3 changes: 3 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ steps:
- 'TAGGED_VERSION=$TAG_NAME'
- 'GCLOUD_PROJECT_ID=$PROJECT_ID'
- 'BUILD_ID=$BUILD_ID'
- 'HELM_HOME=/root/.helm'
dir: './gopath/src/github.com/solo-io/glooshot'
volumes:
- name: 'ssh'
Expand All @@ -126,6 +127,7 @@ steps:
- 'CLOUDSDK_COMPUTE_ZONE=us-central1-a'
- 'CLOUDSDK_CONTAINER_CLUSTER=glooshot-e2e'
- 'BUILD_ID=$BUILD_ID'
- 'HELM_HOME=/root/.helm'
dir: './gopath/src/github.com/solo-io/glooshot'
volumes:
- name: 'ssh'
Expand Down Expand Up @@ -155,6 +157,7 @@ steps:
- 'TAGGED_VERSION=$TAG_NAME'
- 'GCLOUD_PROJECT_ID=$PROJECT_ID'
- 'BUILD_ID=$BUILD_ID'
- 'HELM_HOME=/root/.helm'
dir: './gopath/src/github.com/solo-io/glooshot'
volumes:
- name: 'ssh'
Expand Down
3 changes: 3 additions & 0 deletions install/helm/glooshot/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Generated
values.yaml
Chart.yaml
requirements.yaml
requirements.lock
charts
43 changes: 39 additions & 4 deletions install/helm/glooshot/generate/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ import (
"path"
"strings"

"github.com/solo-io/go-utils/versionutils"

"github.com/solo-io/glooshot/install/helm/glooshot/generate"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
)

var (
valuesTemplate = "install/helm/glooshot/values-template.yaml"
valuesOutput = "install/helm/glooshot/values.yaml"
chartTemplate = "install/helm/glooshot/Chart-template.yaml"
chartOutput = "install/helm/glooshot/Chart.yaml"
valuesTemplate = "install/helm/glooshot/values-template.yaml"
valuesOutput = "install/helm/glooshot/values.yaml"
chartTemplate = "install/helm/glooshot/Chart-template.yaml"
chartOutput = "install/helm/glooshot/Chart.yaml"
requirementsTemplate = "install/helm/glooshot/requirements-template.yaml"
requirementsOutput = "install/helm/glooshot/requirements.yaml"

ifNotPresent = "IfNotPresent"
)
var superglooVersion string

func main() {
var version, repoPrefixOverride = "", ""
Expand All @@ -34,13 +39,19 @@ func main() {
}

}
superglooVersion = mustSuperglooVersion()
log.Printf("Supergloo version is %v", superglooVersion)

log.Printf("Generating helm files.")
if err := generateValuesYaml(version, repoPrefixOverride); err != nil {
log.Fatalf("generating values.yaml failed!: %v", err)
}
if err := generateChartYaml(version); err != nil {
log.Fatalf("generating Chart.yaml failed!: %v", err)
}
if err := generateRequirementsYaml(); err != nil {
log.Fatalf("generating requirements.yaml failed!: %v", err)
}
}

func readYaml(path string, obj interface{}) error {
Expand Down Expand Up @@ -107,9 +118,33 @@ func generateChartYaml(version string) error {
return writeYaml(&chart, chartOutput)
}

func generateRequirementsYaml() error {
var dl generate.DependencyList
if err := readYaml(requirementsTemplate, &dl); err != nil {
return err
}
for i, v := range dl.Dependencies {
if v.Name == "supergloo" {
dl.Dependencies[i].Version = superglooVersion
}
}
return writeYaml(dl, requirementsOutput)
}

// We want to turn "quay.io/solo-io/foo" into "<newPrefix>/foo".
func replacePrefix(repository, newPrefix string) string {
// Remove trailing slash, if present
newPrefix = strings.TrimSuffix(newPrefix, "/")
return strings.Join([]string{newPrefix, path.Base(repository)}, "/")
}
func mustSuperglooVersion() string {
tomlTree, err := versionutils.ParseToml()
if err != nil {
log.Fatalf(err.Error())
}
version, err := versionutils.GetVersion(versionutils.SuperglooPkg, tomlTree)
if err != nil {
log.Fatalf(err.Error())
}
return version
}
12 changes: 12 additions & 0 deletions install/helm/glooshot/generate/requirements.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package generate

type Dependency struct {
Name string `json:"name"`
Version string `json:"version"`
Repository string `json:"repository"`
Condition string `json:"condition,omitempty"`
}

type DependencyList struct {
Dependencies []Dependency `json:"dependencies"`
}
10 changes: 6 additions & 4 deletions install/helm/glooshot/generate/values.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package generate

type Config struct {
Namespace *Namespace `json:"namespace,omitempty"`
Rbac *Rbac `json:"rbac,omitempty"`
Crds *Crds `json:"crds,omitempty"`
Glooshot *Glooshot `json:"glooshot,omitempty"`
Namespace *Namespace `json:"namespace,omitempty"`
Rbac *Rbac `json:"rbac,omitempty"`
Crds *Crds `json:"crds,omitempty"`
Glooshot *Glooshot `json:"glooshot,omitempty"`
Supergloo interface{} `json:"supergloo,omitempty"`
Prometheus interface{} `json:"prometheus,omitempty"`
}

type Namespace struct {
Expand Down
8 changes: 8 additions & 0 deletions install/helm/glooshot/requirements-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencies:
- name: supergloo
repository: https://storage.googleapis.com/supergloo-helm
condition: supergloo.enabled
- name: prometheus
repository: https://kubernetes-charts.storage.googleapis.com/
version: 8.4.1
condition: prometheus.enabled
8 changes: 8 additions & 0 deletions install/helm/glooshot/values-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ glooshot:
pullPolicy: Always
pullSecret: solo-io-docker-secret
replicas: 1

prometheus:
enabled: true
nodeExporter:
enabled: false

supergloo:
enabled: true
44 changes: 44 additions & 0 deletions pkg/cli/cmd/run/run_experiment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package run

import (
"time"

v1 "github.com/solo-io/glooshot/pkg/api/v1"
"github.com/solo-io/glooshot/pkg/cli/flagutils"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
"github.com/spf13/cobra"
)

func Cmd(opts *RunExperimentOptions) *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Aliases: []string{"r"},
Short: "run an experiment and wait for the result",
}

flagutils.AddMetadataFlags(cmd.PersistentFlags(), &opts.Metadata)

return cmd
}

type RunExperimentOptions struct {
Metadata core.Metadata
Faults
}

func experimentFromOpts(opts RunExperimentOptions) (*v1.Experiment, error) {
var (
failureConditions []*v1.FailureCondition
faults []*v1.ExperimentSpec_InjectedFault
duration *time.Duration
)
return &v1.Experiment{
Metadata: opts.Metadata,
Spec: &v1.ExperimentSpec{
Faults: faults,
FailureConditions: failureConditions,
Duration: duration,
TargetMesh: targetMesh,
},
}, nil
}
11 changes: 11 additions & 0 deletions pkg/cli/flagutils/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package flagutils

import (
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
"github.com/spf13/pflag"
)

func AddMetadataFlags(set *pflag.FlagSet, in *core.Metadata) {
set.StringVar(&in.Name, "name", "", "name for the resource")
set.StringVar(&in.Namespace, "namespace", "supergloo-system", "namespace for the resource")
}
11 changes: 10 additions & 1 deletion pkg/setup/options/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package options

import (
"os"
"time"
)

Expand All @@ -14,12 +15,20 @@ type Opts struct {
const (
DefaultSummaryBindAddr = ":8085"
DefaultMeshResourceNamespace = ""
DefaultPrometheusURL = "http://prometheus:9090"
DefaultPrometheusPollingInterval = time.Second * 5

EnvPrometheusURL = "PROMETHEUS_URL"
)

var (
DefaultPrometheusURL = func() string {
if promUrl := os.Getenv(EnvPrometheusURL); promUrl != "" {
return promUrl
}
return "http://glooshot-prometheus-server:9090"
}()
)

func DefaultOpts() Opts {
return Opts{
SummaryBindAddr: DefaultSummaryBindAddr,
Expand Down
14 changes: 4 additions & 10 deletions pkg/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,14 @@ import (

func GetOptions() options.Opts {
var opts options.Opts
flag.StringVar(&opts.SummaryBindAddr, "summary-bind-addr", ":8085", "bind address for serving "+
flag.StringVar(&opts.SummaryBindAddr, "summary-bind-addr", options.DefaultSummaryBindAddr, "bind address for serving "+
"experiment summaries (debug info)")
flag.StringVar(&opts.MeshResourceNamespace, "mesh-namespace", "", "optional, namespace "+
flag.StringVar(&opts.MeshResourceNamespace, "mesh-namespace", options.DefaultMeshResourceNamespace, "optional, namespace "+
"where Glooshot should look for mesh.supergloo.solo.io CRDs, unless otherwise specified, defaults to all namespaces")
flag.StringVar(&opts.PrometheusURL, "prometheus-url", "", "required, url on which to reach the prometheus server")
flag.DurationVar(&opts.PrometheusPollingInterval, "polling-interval", time.Second*5, "optional, "+
flag.StringVar(&opts.PrometheusURL, "prometheus-url", options.DefaultPrometheusURL, "required, url on which to reach the prometheus server")
flag.DurationVar(&opts.PrometheusPollingInterval, "polling-interval", options.DefaultPrometheusPollingInterval, "optional, "+
"interval between polls on running prometheus queries for experiments")
flag.Parse()
if opts.PrometheusURL == "" {
opts.PrometheusURL = os.Getenv(options.EnvPrometheusURL)
if opts.PrometheusURL == "" {
opts.PrometheusURL = options.DefaultPrometheusURL
}
}
return opts
}

Expand Down

0 comments on commit f55f1b2

Please sign in to comment.