Skip to content

Commit

Permalink
Chart annotations (#3724)
Browse files Browse the repository at this point in the history
* update split_resources python file

* add annotations to crds

* add annotations to crds

* add annotations to deployment template

* merge origin

* update chart readme

* remove deployment annotations

* minor tweaks
  • Loading branch information
mwm5945 committed Nov 13, 2021
1 parent a390cbb commit a06f53a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
2 changes: 2 additions & 0 deletions helm-charts/seldon-core-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ helm install seldon-core-operator seldonio/seldon-core-operator --namespace seld
| crd.create | bool | `true` | |
| crd.forceV1 | bool | `false` | |
| crd.forceV1beta1 | bool | `false` | |
| crd.annotations | map | `{}` | Annotations to add to the CRD |
| credentials.gcs.gcsCredentialFileName | string | `"gcloud-application-credentials.json"` | |
| credentials.s3.s3AccessKeyIDName | string | `"awsAccessKeyID"` | |
| credentials.s3.s3SecretAccessKeyName | string | `"awsSecretAccessKey"` | |
Expand Down Expand Up @@ -85,6 +86,7 @@ helm install seldon-core-operator seldonio/seldon-core-operator --namespace seld
| manager.leaderElectionID | string | `"a33bd623.machinelearning.seldon.io"` | |
| manager.memoryLimit | string | `"300Mi"` | |
| manager.memoryRequest | string | `"200Mi"` | |
| manager.annotations | map | `{}` | Annotations to add to the deployment template spec |
| managerCreateResources | bool | `false` | |
| managerUserID | int | `8888` | |
| namespaceOverride | string | `""` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ metadata:
annotations:
cert-manager.io/inject-ca-from: '{{ include "seldon.namespace" . }}/seldon-serving-cert'
controller-gen.kubebuilder.io/version: v0.5.0
{{- with .Values.crd.annotations }}
{{- toYaml . | nindent 4}}
{{- end }}
labels:
app: seldon
app.kubernetes.io/instance: '{{ .Release.Name }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ metadata:
annotations:
cert-manager.io/inject-ca-from: '{{ include "seldon.namespace" . }}/seldon-serving-cert'
controller-gen.kubebuilder.io/version: v0.5.0
{{- with .Values.crd.annotations }}
{{- toYaml . | nindent 4}}
{{- end }}
name: seldondeployments.machinelearning.seldon.io
spec:
group: machinelearning.seldon.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ spec:
template:
metadata:
annotations:
{{- with .Values.manager.annotations }}
{{- toYaml . | nindent 4}}
{{- end }}
prometheus.io/scrape: 'true'
sidecar.istio.io/inject: 'false'
labels:
Expand Down
2 changes: 2 additions & 0 deletions helm-charts/seldon-core-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ manager:
memoryRequest: 200Mi
logLevel: INFO
leaderElectionID: a33bd623.machinelearning.seldon.io
annotations: {}
rbac:
configmap:
create: true
Expand Down Expand Up @@ -161,6 +162,7 @@ crd:
# Whether to force the use of the v1beta1 or v1 CRD.
forceV1: false
forceV1beta1: false
annotations: {} # Annotations to add to the CRD if not created by the Manager

# Warning: credentials will be depricated soon, please use defaultEnvSecretRefName above
# For more info please check the documentation
Expand Down
51 changes: 41 additions & 10 deletions operator/helm/split_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import yaml

parser = argparse.ArgumentParser()
parser.add_argument("--prefix", default="xx", help="find files matching prefix")
parser.add_argument("--prefix", default="xx",
help="find files matching prefix")
parser.add_argument("--folder", required=True, help="Output folder")
args, _ = parser.parse_known_args()

Expand All @@ -29,6 +30,9 @@
HELM_CREATERESOURCES_RBAC_IF_START = "{{- if .Values.managerCreateResources }}\n"
HELM_K8S_V1_CRD_IF_START = '{{- if or (ge (int (regexFind "[0-9]+" .Capabilities.KubeVersion.Minor)) 18) (.Values.crd.forcev1) }}\n'
HELM_K8S_V1BETA1_CRD_IF_START = '{{- if or (lt (int (regexFind "[0-9]+" .Capabilities.KubeVersion.Minor)) 18) (.Values.crd.forcev1beta1) }}\n'
HELM_CRD_ANNOTATIONS_WITH_START = '{{- with .Values.crd.annotations }}\n'
HELM_ANNOTATIONS_TOYAML = '{{- toYaml . | nindent 4}}\n'
HELM_CONTROLER_DEP_ANNOTATIONS_WITH_START = '{{- with .Values.manager.annotations }}\n'
HELM_IF_END = "{{- end }}\n"

HELM_ENV_SUBST = {
Expand Down Expand Up @@ -96,7 +100,8 @@ def helm_namespace_override():
webhookData
+ '{{- $altNames := list ( printf "seldon-webhook-service.%s" (include "seldon.namespace" .) ) ( printf "seldon-webhook-service.%s.svc" (include "seldon.namespace" .) ) -}}\n'
)
webhookData = webhookData + '{{- $ca := genCA "custom-metrics-ca" 365 -}}\n'
webhookData = webhookData + \
'{{- $ca := genCA "custom-metrics-ca" 365 -}}\n'
webhookData = (
webhookData
+ '{{- $cert := genSignedCert "seldon-webhook-service" nil $altNames 365 $ca -}}\n'
Expand All @@ -108,7 +113,8 @@ def helm_namespace_override():
kind = res["kind"].lower()
name = res["metadata"]["name"].lower()
version = res["apiVersion"]
filename = args.folder + "/" + (kind + "_" + name).lower() + ".yaml"
filename = args.folder + "/" + \
(kind + "_" + name).lower() + ".yaml"
print(filename)
print(version)
if (
Expand Down Expand Up @@ -201,7 +207,8 @@ def helm_namespace_override():
if portSpec["name"] == "webhook-server":
portSpec["containerPort"] = helm_value("webhook.port")
for argIdx in range(
0, len(res["spec"]["template"]["spec"]["containers"][0]["args"])
0, len(res["spec"]["template"]["spec"]
["containers"][0]["args"])
):
if (
res["spec"]["template"]["spec"]["containers"][0]["args"][argIdx]
Expand All @@ -216,7 +223,8 @@ def helm_namespace_override():

if kind == "configmap" and name == "seldon-config":
res["data"]["credentials"] = helm_value_json("credentials")
res["data"]["predictor_servers"] = helm_value_json("predictor_servers")
res["data"]["predictor_servers"] = helm_value_json(
"predictor_servers")
res["data"]["storageInitializer"] = helm_value_json(
"storageInitializer"
)
Expand All @@ -239,7 +247,8 @@ def helm_namespace_override():
res["roleRef"]["name"] + "-" + helm_namespace_override()
)
if name == "seldon-manager-rolebinding":
res["subjects"][0]["name"] = helm_value("serviceAccount.name")
res["subjects"][0]["name"] = helm_value(
"serviceAccount.name")
res["subjects"][0]["namespace"] = helm_namespace_override()
elif name != "seldon-spartakus-volunteer":
res["subjects"][0]["namespace"] = helm_namespace_override()
Expand All @@ -252,7 +261,8 @@ def helm_namespace_override():
or name == "seldon1-manager-sas-rolebinding"
or name == "seldon-leader-election-rolebinding"
):
res["subjects"][0]["name"] = helm_value("serviceAccount.name")
res["subjects"][0]["name"] = helm_value(
"serviceAccount.name")
res["subjects"][0]["namespace"] = helm_namespace_override()

# Update webhook certificates
Expand Down Expand Up @@ -301,7 +311,8 @@ def helm_namespace_override():

# Update webhook service port
if kind == "service" and name == "seldon-webhook-service":
res["spec"]["ports"][0]["targetPort"] = helm_value("webhook.port")
res["spec"]["ports"][0]["targetPort"] = helm_value(
"webhook.port")

fdata = yaml.dump(res, width=1000)

Expand Down Expand Up @@ -392,7 +403,13 @@ def helm_namespace_override():
fdata = (
HELM_CRD_IF_START
+ HELM_K8S_V1BETA1_CRD_IF_START
+ fdata
+ re.sub(
r"(.*controller-gen.kubebuilder.io/version.*\n)",
r"\1" + HELM_CRD_ANNOTATIONS_WITH_START +
HELM_ANNOTATIONS_TOYAML + HELM_IF_END,
fdata,
re.M,
)
+ HELM_IF_END
+ HELM_IF_END
)
Expand All @@ -403,7 +420,13 @@ def helm_namespace_override():
fdata = (
HELM_CRD_IF_START
+ HELM_K8S_V1_CRD_IF_START
+ fdata
+ re.sub(
r"(.*controller-gen.kubebuilder.io/version.*\n)",
r"\1" + HELM_CRD_ANNOTATIONS_WITH_START +
HELM_ANNOTATIONS_TOYAML + HELM_IF_END,
fdata,
re.M,
)
+ HELM_IF_END
+ HELM_IF_END
)
Expand All @@ -425,6 +448,14 @@ def helm_namespace_override():
re.M,
)

fdata = re.sub(
r"(.*template:\n.*metadata:\n.*annotations:\n)",
r"\1" + HELM_CONTROLER_DEP_ANNOTATIONS_WITH_START +
HELM_ANNOTATIONS_TOYAML + HELM_IF_END,
fdata,
re.M,
)

# make sure webhook is not quoted as its an int
fdata = fdata.replace(
"'{{ .Values.webhook.port }}'", "{{ .Values.webhook.port }}"
Expand Down

0 comments on commit a06f53a

Please sign in to comment.