Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions datadog/metric/metric
Original file line number Diff line number Diff line change
Expand Up @@ -263,41 +263,43 @@ transform_response() {
echo "$response" | jq '
(.data.attributes.times // []) as $times |
(.data.attributes.values // [[]]) as $values |
(.data.attributes.series // []) | map({
selector: (
if .group_tags then
if (.group_tags | type) == "array" then
if (.group_tags | length) == 0 then
{}
(.data.attributes.series // []) | to_entries | map(
.key as $idx |
.value | {
selector: (
if .group_tags then
if (.group_tags | type) == "array" then
if (.group_tags | length) == 0 then
{}
else
# Convert array of "key:value" strings to object
.group_tags | map(split(":") | {(.[0]): .[1]}) | add
end
else
# Convert array of "key:value" strings to object
.group_tags | map(split(":") | {(.[0]): .[1]}) | add
.group_tags
end
elif .scope then
if (.scope | type) == "string" then
.scope | split(",") | map(split(":") | {(.[0]): .[1]}) | add
else
.scope
end
else
.group_tags
{}
end
elif .scope then
if (.scope | type) == "string" then
.scope | split(",") | map(split(":") | {(.[0]): .[1]}) | add
),
data: (
if ($values | length) > 0 and ($times | length) > 0 then
[range($times | length)] | map({
timestamp: ($times[.] / 1000 | todate),
value: ($values[$idx][.] // 0)
})
else
.scope
[]
end
else
{}
end
)
} + {
data: (
if ($values | length) > 0 and ($times | length) > 0 then
[range($times | length)] | map({
timestamp: ($times[.] / 1000 | todate),
value: $values[0][.]
})
else
[]
end
)
})'
)
}
)'
}

transformed_results=$(transform_response "$response")
Expand Down
17 changes: 17 additions & 0 deletions k8s/deployment/notify_active_domains
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -euo pipefail

DOMAINS=$(echo "$CONTEXT" | jq .scope.domains)

if [[ "$DOMAINS" == "null" || "$DOMAINS" == "[]" ]]; then
return
fi

echo "$DOMAINS" | jq -r '.[] | "\(.id)|\(.name)"' | while IFS='|' read -r domain_id domain_name; do
echo "Configuring domain: $domain_name"

np scope domain patch --id "$domain_id" --body '{"status": "active"}'

echo "Successfully configured domain: $domain_name"
done
114 changes: 114 additions & 0 deletions k8s/deployment/templates/blue-green-ingress.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,117 @@ spec:
port:
name: use-annotation
{{- end }}

{{ if .scope.capabilities.additional_ports }}
{{ range .scope.capabilities.additional_ports }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: k-8-s-{{ $.scope.slug }}-{{ $.scope.id }}-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}-{{ $.ingress_visibility }}
namespace: {{ $.k8s_namespace }}
labels:
nullplatform: "true"
account: {{ $.account.slug }}
account_id: "{{ $.account.id }}"
namespace: {{ $.namespace.slug }}
namespace_id: "{{ $.namespace.id }}"
application: {{ $.application.slug }}
application_id: "{{ $.application.id }}"
scope: {{ $.scope.slug }}
scope_id: "{{ $.scope.id }}"
{{- $global := index $.k8s_modifiers "global" }}
{{- if $global }}
{{- $labels := index $global "labels" }}
{{- if $labels }}
{{ data.ToYAML $labels | indent 4 }}
{{- end }}
{{- end }}
{{- $ingress := index $.k8s_modifiers "ingress" }}
{{- if $ingress }}
{{- $labels := index $ingress "labels" }}
{{- if $labels }}
{{ data.ToYAML $labels | indent 4 }}
{{- end }}
{{- end }}
annotations:
alb.ingress.kubernetes.io/actions.bg-deployment-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}: >-
{"type":"forward","forwardConfig":{"targetGroups":[
{"serviceName":"d-{{ $.scope.id }}-{{ $.blue_deployment_id }}-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}","servicePort":{{ .port }},"weight":{{ sub 100 $.deployment.strategy_data.desired_switched_traffic }}},
{"serviceName":"d-{{ $.scope.id }}-{{ $.deployment.id }}-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}","servicePort":{{ .port }},"weight":{{ $.deployment.strategy_data.desired_switched_traffic }}}
]}}
alb.ingress.kubernetes.io/actions.response-404: '{"type":"fixed-response","fixedResponseConfig":{"contentType":"text/plain","statusCode":"404","messageBody":"404 scope not found or has not been deployed yet"}}'
alb.ingress.kubernetes.io/group.name: {{ $.alb_name }}
alb.ingress.kubernetes.io/load-balancer-name: {{ $.alb_name }}
alb.ingress.kubernetes.io/scheme: {{ $.ingress_visibility }}
alb.ingress.kubernetes.io/target-node-labels: account={{ $.account.slug }},namespace={{ $.namespace.slug }},application={{ $.application.slug }},account_id={{ $.account.id }},namespace_id={{ $.namespace.id }},application_id={{ $.application.id }},scope={{ $.scope.slug }},scope_id={{ $.scope.id }},nullplatform=true
alb.ingress.kubernetes.io/target-type: ip
{{ if eq .type "HTTP" }}
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80},{"HTTPS":443}]'
alb.ingress.kubernetes.io/ssl-redirect: "443"
{{ else if eq .type "GRPC" }}
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":{{ .port }}}]'
alb.ingress.kubernetes.io/backend-protocol-version: GRPC
alb.ingress.kubernetes.io/load-balancer-attributes: routing.http2.enabled=true
{{- $global := index $.k8s_modifiers "global" }}
{{- if $global }}
{{- $annotations := index $global "annotations" }}
{{- if $annotations }}
{{ data.ToYAML $annotations | indent 4 }}
{{- end }}
{{- end }}
{{- $ingress := index $.k8s_modifiers "ingress" }}
{{- if $ingress }}
{{- $annotations := index $ingress "annotations" }}
{{- if $annotations }}
{{ data.ToYAML $annotations | indent 4 }}
{{- end }}
{{- end }}
{{ end }}
spec:
ingressClassName: alb
rules:
- host: {{ $.scope.domain }}
http:
paths:
{{ if eq .type "HTTP" }}
- path: /{{ .port }}
pathType: Prefix
backend:
service:
name: bg-deployment-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}
port:
name: use-annotation
{{ else if eq .type "GRPC" }}
- path: /
pathType: Prefix
backend:
service:
name: bg-deployment-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}
port:
name: use-annotation
{{ end }}
{{- range $.scope.domains }}
- host: {{ .name }}
http:
paths:
{{ if eq $.type "HTTP" }}
- path: /{{ $.port }}
pathType: Prefix
backend:
service:
name: bg-deployment-{{ if eq $.type "HTTP" }}http{{ else }}grpc{{ end }}-{{ $.port }}
port:
name: use-annotation
{{ else if eq $.type "GRPC" }}
- path: /
pathType: Prefix
backend:
service:
name: bg-deployment-{{ if eq $.type "HTTP" }}http{{ else }}grpc{{ end }}-{{ $.port }}
port:
name: use-annotation
{{ end }}
{{- end }}
{{ end }}
{{ end }}
65 changes: 64 additions & 1 deletion k8s/deployment/templates/deployment.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ spec:
- name: http
securityContext:
runAsUser: 0
image: public.ecr.aws/nullplatform/k8s-traffic-manager:latest
image: {{ .traffic_image }}
ports:
- containerPort: 80
protocol: TCP
Expand Down Expand Up @@ -158,6 +158,63 @@ spec:
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always

{{ if .scope.capabilities.additional_ports }}
{{ range .scope.capabilities.additional_ports }}
{{ if eq .type "GRPC" }}
- name: grpc-{{ .port }}
securityContext:
runAsUser: 0
image: {{ $.traffic_image }}
ports:
- containerPort: {{ .port }}
protocol: TCP
env:
- name: HEALTH_CHECK_TYPE
value: grpc
- name: GRACE_PERIOD
value: '15'
- name: LISTENER_PROTOCOL
value: grpc
- name: LISTENER_PORT
value: '{{ .port }}'
resources:
limits:
cpu: 93m
memory: 64Mi
requests:
cpu: 31m
livenessProbe:
grpc:
port: {{ .port }}
timeoutSeconds: 5
periodSeconds: 10
initialDelaySeconds: {{ $.scope.capabilities.health_check.initial_delay_seconds }}
successThreshold: 1
failureThreshold: 9
readinessProbe:
grpc:
port: {{ .port }}
timeoutSeconds: 5
periodSeconds: 10
initialDelaySeconds: {{ $.scope.capabilities.health_check.initial_delay_seconds }}
successThreshold: 1
failureThreshold: 3
startupProbe:
grpc:
port: {{ .port }}
timeoutSeconds: 5
periodSeconds: 10
initialDelaySeconds: {{ $.scope.capabilities.health_check.initial_delay_seconds }}
successThreshold: 1
failureThreshold: 90
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
{{ end }}
{{ end }}
{{ end }}

- name: application
envFrom:
- secretRef:
Expand All @@ -169,6 +226,12 @@ spec:
ports:
- containerPort: 8080
protocol: TCP
{{ if .scope.capabilities.additional_ports }}
{{ range .scope.capabilities.additional_ports }}
- containerPort: {{ .port }}
protocol: TCP
{{ end }}
{{ end }}
resources:
limits:
cpu: {{ .scope.capabilities.cpu_millicores }}m
Expand Down
88 changes: 87 additions & 1 deletion k8s/deployment/templates/initial-ingress.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,90 @@ spec:
name: d-{{ $.scope.id }}-{{ $.deployment.id }}
port:
number: 8080
{{- end }}
{{- end }}
{{ if .scope.capabilities.additional_ports }}
{{ range .scope.capabilities.additional_ports }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: k-8-s-{{ $.scope.slug }}-{{ $.scope.id }}-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}-{{ $.ingress_visibility }}
namespace: {{ $.k8s_namespace }}
labels:
nullplatform: "true"
account: {{ $.account.slug }}
account_id: "{{ $.account.id }}"
namespace: {{ $.namespace.slug }}
namespace_id: "{{ $.namespace.id }}"
application: {{ $.application.slug }}
application_id: "{{ $.application.id }}"
scope: {{ $.scope.slug }}
scope_id: "{{ $.scope.id }}"
{{- $global := index $.k8s_modifiers "global" }}
{{- if $global }}
{{- $labels := index $global "labels" }}
{{- if $labels }}
{{ data.ToYAML $labels | indent 4 }}
{{- end }}
{{- end }}
{{- $ingress := index $.k8s_modifiers "ingress" }}
{{- if $ingress }}
{{- $labels := index $ingress "labels" }}
{{- if $labels }}
{{ data.ToYAML $labels | indent 4 }}
{{- end }}
{{- end }}
annotations:
alb.ingress.kubernetes.io/group.name: {{ $.alb_name }}
{{ if eq .type "HTTP" }}
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80},{"HTTPS":443}]'
{{ else if eq .type "GRPC" }}
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":{{ .port }}}]'
alb.ingress.kubernetes.io/backend-protocol-version: GRPC
alb.ingress.kubernetes.io/load-balancer-attributes: routing.http2.enabled=true
{{ end }}
alb.ingress.kubernetes.io/load-balancer-name: {{ $.alb_name }}
alb.ingress.kubernetes.io/scheme: {{ $.ingress_visibility }}
alb.ingress.kubernetes.io/target-node-labels: account={{ $.account.slug }},namespace={{ $.namespace.slug }},application={{ $.application.slug }},account_id={{ $.account.id }},namespace_id={{ $.namespace.id }},application_id={{ $.application.id }},scope={{ $.scope.slug }},scope_id={{ $.scope.id }},nullplatform=true
alb.ingress.kubernetes.io/target-type: ip
{{- $global := index $.k8s_modifiers "global" }}
{{- if $global }}
{{- $annotations := index $global "annotations" }}
{{- if $annotations }}
{{ data.ToYAML $annotations | indent 4 }}
{{- end }}
{{- end }}
{{- $ingress := index $.k8s_modifiers "ingress" }}
{{- if $ingress }}
{{- $annotations := index $ingress "annotations" }}
{{- if $annotations }}
{{ data.ToYAML $annotations | indent 4 }}
{{- end }}
{{- end }}
spec:
ingressClassName: alb
rules:
- host: {{ $.scope.domain }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: d-{{ $.scope.id }}-{{ $.deployment.id }}-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}
port:
number: {{ .port }}
{{- range $.scope.domains }}
- host: {{ .name }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: d-{{ $.scope.id }}-{{ $.deployment.id }}-{{ if eq .type "HTTP" }}http{{ else }}grpc{{ end }}-{{ .port }}
port:
number: {{ .port }}
{{- end }}
{{ end }}
{{ end }}
Loading