mirror of
https://github.com/carlosedp/cluster-monitoring.git
synced 2024-11-20 19:07:17 +01:00
Improve Makefile. Reformat code.
This commit is contained in:
parent
d4be411a81
commit
8c418b73bb
58
Makefile
58
Makefile
@ -1,55 +1,65 @@
|
||||
JSONNET_FMT := jsonnet fmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
|
||||
|
||||
GOPATH ?= `$(pwd)`
|
||||
|
||||
JSONNET_BIN := $(GOPATH)/bin/jsonnet
|
||||
JB_BINARY := $(GOPATH)/bin/jb
|
||||
|
||||
.PHONY: generate vendor fmt manifests
|
||||
JSONNET_FMT := $(GOPATH)/bin/jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
|
||||
|
||||
all: manifests
|
||||
.PHONY: generate vendor fmt manifests help
|
||||
|
||||
manifests: jsonnet
|
||||
all: manifests ## Builds the manifests
|
||||
|
||||
help: # Show help
|
||||
@echo "Makefile targets:"
|
||||
@echo ""
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||
|
||||
manifests: $(JSONNET_BIN) ## Builds the manifests
|
||||
rm -rf manifests
|
||||
./scripts/build.sh main.jsonnet $(JSONNET_BIN)
|
||||
|
||||
update: jsonnet_bundler
|
||||
jb update
|
||||
update_libs: $(JB_BINARY) ## Updates vendor libs. Require a regeneration of the manifests
|
||||
$(JB_BINARY) update
|
||||
|
||||
vendor: jsonnet_bundler jsonnetfile.json jsonnetfile.lock.json
|
||||
vendor: $(JB_BINARY) jsonnetfile.json jsonnetfile.lock.json ## Download vendor libs
|
||||
rm -rf vendor
|
||||
$(JB_BINARY) install
|
||||
|
||||
fmt:
|
||||
find . -name 'vendor' -prune -o -name '*.libsonnet' -o -name '*.jsonnet' -print | xargs -n 1 -- $(JSONNET_FMT) -i
|
||||
fmt: ## Formats all jsonnet and libsonnet files (except on vendor dir)
|
||||
@echo "Formatting jsonnet files"
|
||||
@find . -name 'vendor' -prune -o -name '*.libsonnet' -o -name '*.jsonnet' -print | xargs -n 1 -- $(JSONNET_FMT) -i
|
||||
|
||||
deploy: manifests
|
||||
deploy: manifests ## Rebuilds manifests and deploy to configured cluster
|
||||
kubectl apply -f ./manifests/
|
||||
echo "Will wait 40 seconds to reapply manifests"
|
||||
sleep 40
|
||||
kubectl apply -f ./manifests/
|
||||
|
||||
teardown:
|
||||
teardown: ## Delete all monitoring stack resources from configured cluster
|
||||
kubectl delete -f ./manifests/
|
||||
|
||||
tar: manifests
|
||||
rm -rf manifests.tar
|
||||
tar -cf manifests.tar manifests
|
||||
tar: manifests ## Generates a .tar.gz from manifests dir
|
||||
rm -rf manifests.tar.gz
|
||||
tar -cfz manifests.tar.gz manifests
|
||||
|
||||
jsonnet_bundler:
|
||||
ifeq (, $(shell which jb))
|
||||
$(JB_BINARY): ## Installs jsonnet-bundler utility
|
||||
@echo "Installing jsonnet-bundler"
|
||||
@go get -u github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
|
||||
endif
|
||||
|
||||
jsonnet:
|
||||
ifeq (, $(shell which jsonnet))
|
||||
$(JSONNET_BIN): ## Installs jsonnet and jsonnetfmt utility
|
||||
@echo "Installing jsonnet"
|
||||
@go get github.com/google/go-jsonnet/cmd/jsonnet
|
||||
@go get github.com/brancz/gojsontoyaml
|
||||
endif
|
||||
@go get -u github.com/google/go-jsonnet/cmd/jsonnet
|
||||
@go get -u github.com/google/go-jsonnet/cmd/jsonnetfmt
|
||||
@go get -u github.com/brancz/gojsontoyaml
|
||||
|
||||
change_suffix:
|
||||
update_tools: ## Updates jsonnet, jsonnetfmt and jb utilities
|
||||
@echo "Updating jsonnet"
|
||||
@go get -u github.com/google/go-jsonnet/cmd/jsonnet
|
||||
@go get -u github.com/google/go-jsonnet/cmd/jsonnetfmt
|
||||
@go get -u github.com/brancz/gojsontoyaml
|
||||
@go get -u github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
|
||||
|
||||
change_suffix: ## Changes suffix for the ingress
|
||||
@perl -p -i -e 's/^(\s*)\-\ host:.*/\1- host: alertmanager.${IP}.nip.io/g' manifests/ingress-alertmanager.yaml manifests/ingress-prometheus.yaml manifests/ingress-grafana.yaml
|
||||
@echo "Ingress IPs changed to [service].${IP}.nip.io"
|
||||
${K3S} kubectl apply -f manifests/ingress-alertmanager.yaml
|
||||
|
@ -20,14 +20,16 @@ local utils = import 'utils.libsonnet';
|
||||
|
||||
clusterRole:
|
||||
utils.newClusterRole('arm-exporter', [
|
||||
{apis: ['authentication.k8s.io'],
|
||||
{
|
||||
apis: ['authentication.k8s.io'],
|
||||
res: ['tokenreviews'],
|
||||
verbs: ['create']
|
||||
verbs: ['create'],
|
||||
},
|
||||
{apis: ['authorization.k8s.io'],
|
||||
{
|
||||
apis: ['authorization.k8s.io'],
|
||||
res: ['subjectaccessreviews'],
|
||||
verbs: ['create']
|
||||
}
|
||||
verbs: ['create'],
|
||||
},
|
||||
], null),
|
||||
|
||||
clusterRoleBinding:
|
||||
@ -86,9 +88,10 @@ local utils = import 'utils.libsonnet';
|
||||
service.mixin.spec.withClusterIp('None'),
|
||||
|
||||
serviceMonitor:
|
||||
utils.newServiceMonitorHTTPS('arm-exporter',
|
||||
utils.newServiceMonitorHTTPS(
|
||||
'arm-exporter',
|
||||
$._config.namespace,
|
||||
{'k8s-app': 'arm-exporter'},
|
||||
{ 'k8s-app': 'arm-exporter' },
|
||||
$._config.namespace,
|
||||
'https',
|
||||
'https',
|
||||
|
@ -82,19 +82,21 @@ local utils = import 'utils.libsonnet';
|
||||
utils.newServiceMonitor(
|
||||
'elasticsearch',
|
||||
$._config.namespace,
|
||||
{'k8s-app': 'elasticsearch-exporter'},
|
||||
{ 'k8s-app': 'elasticsearch-exporter' },
|
||||
'monitoring',
|
||||
'es-metrics',
|
||||
'http'),
|
||||
'http'
|
||||
),
|
||||
|
||||
serviceMonitorFluentd:
|
||||
utils.newServiceMonitor(
|
||||
'fluentd-es',
|
||||
$._config.namespace,
|
||||
{'k8s-app': 'fluentd-es'},
|
||||
{ 'k8s-app': 'fluentd-es' },
|
||||
'logging',
|
||||
'metrics',
|
||||
'http'),
|
||||
'http'
|
||||
),
|
||||
},
|
||||
// Add Prometheus monitoring rules for ElasticSearch
|
||||
prometheusRules+:: {
|
||||
|
@ -13,7 +13,7 @@ local utils = import 'utils.libsonnet';
|
||||
|
||||
metallbExporter+:: {
|
||||
serviceMonitor:
|
||||
utils.newServiceMonitor('metallb', $._config.namespace, {'k8s-app': 'metallb-controller'}, 'metallb-system', 'http', 'http'),
|
||||
utils.newServiceMonitor('metallb', $._config.namespace, { 'k8s-app': 'metallb-controller' }, 'metallb-system', 'http', 'http'),
|
||||
|
||||
service:
|
||||
local service = k.core.v1.service;
|
||||
|
@ -12,6 +12,6 @@ local utils = import 'utils.libsonnet';
|
||||
|
||||
traefikExporter+:: {
|
||||
serviceMonitor:
|
||||
utils.newServiceMonitor('traefik', $._config.namespace, {'app': 'traefik'}, 'kube-system', 'metrics', 'http'),
|
||||
utils.newServiceMonitor('traefik', $._config.namespace, { app: 'traefik' }, 'kube-system', 'metrics', 'http'),
|
||||
},
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ local utils = import 'utils.libsonnet';
|
||||
|
||||
upsExporter+:: {
|
||||
serviceMonitor:
|
||||
utils.newServiceMonitor('ups-exporter', $._config.namespace, {'k8s-app': 'ups-exporter'}, $._config.namespace, 'metrics', 'http'),
|
||||
utils.newServiceMonitor('ups-exporter', $._config.namespace, { 'k8s-app': 'ups-exporter' }, $._config.namespace, 'metrics', 'http'),
|
||||
|
||||
service:
|
||||
local service = k.core.v1.service;
|
||||
|
@ -5,7 +5,8 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
generate(kp):: (
|
||||
{
|
||||
[std.asciiLower(module) + '-' + name]: kp[module][name]
|
||||
for module in std.objectFieldsAll(kp) if !std.startsWith(module, '_')
|
||||
for module in std.objectFieldsAll(kp)
|
||||
if !std.startsWith(module, '_')
|
||||
for name in std.objectFields(kp[module])
|
||||
}
|
||||
),
|
||||
@ -42,7 +43,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
+ policyRule.withResources([r for r in resources])
|
||||
+ policyRule.withVerbs([v for v in verbs]);
|
||||
|
||||
local r = [ p(pol.apis, pol.res, pol.verbs) for pol in roles ];
|
||||
local r = [p(pol.apis, pol.res, pol.verbs) for pol in roles];
|
||||
|
||||
local rules = r;
|
||||
|
||||
@ -63,7 +64,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
+ clusterRoleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io')
|
||||
+ clusterRoleBinding.mixin.roleRef.withName(clusterRole)
|
||||
+ clusterRoleBinding.mixin.roleRef.mixinInstance({ kind: 'ClusterRole' })
|
||||
+ clusterRoleBinding.withSubjects([{ kind: 'ServiceAccount', 'name': serviceAccount, 'namespace': serviceAccountNamespace }])
|
||||
+ clusterRoleBinding.withSubjects([{ kind: 'ServiceAccount', name: serviceAccount, namespace: serviceAccountNamespace }])
|
||||
),
|
||||
|
||||
// Creates endpoint objects
|
||||
@ -121,7 +122,7 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
I + ingress.mixin.spec.withTls(
|
||||
ingressTls.new() +
|
||||
ingressTls.withHosts(host) +
|
||||
(if S != '' then {'secretName': S} else {})
|
||||
(if S != '' then { secretName: S } else {})
|
||||
)
|
||||
),
|
||||
|
||||
@ -136,7 +137,8 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
{
|
||||
'tls.crt': std.base64(crt),
|
||||
'tls.key': std.base64(key),
|
||||
})
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
// Creates new basic deployments
|
||||
@ -152,10 +154,10 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
|
||||
local c = [con];
|
||||
|
||||
local d = deployment.new(name, 1, c, {'app': name})
|
||||
local d = deployment.new(name, 1, c, { app: name })
|
||||
+ deployment.mixin.metadata.withNamespace(namespace)
|
||||
+ deployment.mixin.metadata.withLabels({'app': name})
|
||||
+ deployment.mixin.spec.selector.withMatchLabels({'app': name})
|
||||
+ deployment.mixin.metadata.withLabels({ app: name })
|
||||
+ deployment.mixin.spec.selector.withMatchLabels({ app: name })
|
||||
+ deployment.mixin.spec.strategy.withType('RollingUpdate')
|
||||
+ deployment.mixin.spec.template.spec.withRestartPolicy('Always');
|
||||
d
|
||||
@ -166,9 +168,9 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
local servicePort = k.core.v1.service.mixin.spec.portsType;
|
||||
local p = servicePort.newNamed(name, port, port);
|
||||
|
||||
local s = service.new(name, {'app': name}, p)
|
||||
local s = service.new(name, { app: name }, p)
|
||||
+ service.mixin.metadata.withNamespace(namespace)
|
||||
+ service.mixin.metadata.withLabels({'app': name});
|
||||
+ service.mixin.metadata.withLabels({ app: name });
|
||||
s
|
||||
),
|
||||
|
||||
@ -181,11 +183,11 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
name: name,
|
||||
namespace: namespace,
|
||||
labels: {
|
||||
'app': name,
|
||||
app: name,
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
jobLabel: name+'-exporter',
|
||||
jobLabel: name + '-exporter',
|
||||
selector: {
|
||||
matchLabels: matchLabel,
|
||||
},
|
||||
@ -216,20 +218,20 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
bearerTokenFile: token,
|
||||
tlsConfig: {
|
||||
insecureSkipVerify: true,
|
||||
}
|
||||
},
|
||||
}],
|
||||
}
|
||||
},
|
||||
};
|
||||
std.mergePatch(s, t)
|
||||
// s + t
|
||||
),
|
||||
|
||||
|
||||
# Adds arguments to a container in a deployment
|
||||
# args is an array of arguments in the format
|
||||
# ["arg1","arg2",]
|
||||
// Adds arguments to a container in a deployment
|
||||
// args is an array of arguments in the format
|
||||
// ["arg1","arg2",]
|
||||
addArguments(deployment, container, args):: (
|
||||
{spec+: {
|
||||
{ spec+: {
|
||||
template+: {
|
||||
spec+: {
|
||||
containers:
|
||||
@ -242,14 +244,14 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
),
|
||||
},
|
||||
},
|
||||
}}
|
||||
} }
|
||||
),
|
||||
|
||||
# Adds environment variables to a container in a deployment
|
||||
# envs is an array of environment variables in the format
|
||||
# [{name: 'VARNAME', value: 'var_value'},{...},]
|
||||
// Adds environment variables to a container in a deployment
|
||||
// envs is an array of environment variables in the format
|
||||
// [{name: 'VARNAME', value: 'var_value'},{...},]
|
||||
addEnviromnentVars(deployment, container, envs):: (
|
||||
{spec+: {
|
||||
{ spec+: {
|
||||
template+: {
|
||||
spec+: {
|
||||
containers:
|
||||
@ -262,6 +264,6 @@ local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
|
||||
),
|
||||
},
|
||||
},
|
||||
}}
|
||||
} }
|
||||
),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user