Skip to content

Commit 5564fbd

Browse files
authored
Move autogeneration features to *production* (#735)
1 parent 4311d3d commit 5564fbd

File tree

6 files changed

+104
-220
lines changed

6 files changed

+104
-220
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
# SAS Viya Monitoring for Kubernetes
2+
## unreleased
3+
* **Overall**
4+
* [ANNOUNCEMENT] As announced previously, this project now *requires* the `yq` command-line processor for YAML. Specifically, a recent version (4.32+) of the [Golang-based (Mike Farah) version of `yq`](https://github.com/mikefarah/yq)
5+
needs to be installed. While this utility is *currently* only used in a few places, we expect its use to become
6+
much more extensive over time.
7+
* [FEATURE] The auto-generation of Ingress resources for the web applications has moved from *experimental*
8+
to *production* status. As noted earlier, this feature requires the `yq` utility. See the
9+
[Configure Ingress Access to Web Applications](https://documentation.sas.com/?cdcId=obsrvcdc&cdcVersion=v_003&docsetId=obsrvdply&docsetTarget=n0auhd4hutsf7xn169hfvriysz4e.htm#n0jiph3lcb5rmsn1g71be3cesmo8)
10+
topic within the Help Center documentation for further information.
11+
* [FEATURE] The auto-generation of storageClass references for PVC definitions has moved from *experimental*
12+
to *production* status. As noted earlier, this feature requires the `yq` utility. See the
13+
[Customize StorageClass](https://documentation.sas.com/?cdcId=obsrvcdc&cdcVersion=v_003&docsetId=obsrvdply&docsetTarget=n0auhd4hutsf7xn169hfvriysz4e.htm#p1lvxtk81r8jgun1d789fqaz3lq1)
14+
topic within the Help Center documentation for further information.
215

316

417
## unreleased

autogenerate.md

Lines changed: 0 additions & 186 deletions
This file was deleted.

bin/autogenerate-include.sh

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ function checkYqVersion {
2424

2525
export -f checkYqVersion
2626

27+
function create_ingress_certs {
28+
local certFile keyFile namespace secretName
29+
30+
namespace="$1"
31+
secretName="$2"
32+
certFile="${3:-$INGRESS_CERT}"
33+
keyFile="${4:-$INGRESS_KEY}"
34+
35+
if [ -f "$certFile" ] && [ -f "$keyFile" ]; then
36+
kubectl delete secret "$secretName" --namespace "$namespace" --ignore-not-found
37+
kubectl create secret tls "$secretName" --namespace "$namespace" --key="$keyFile" --cert="$certFile"
38+
kubectl -n $namespace label secret $secretName managed-by="v4m-es-script"
39+
elif [ ! -z "$certFile$keyFile" ]; then
40+
log_warn "Missing Ingress certificate file; specified Ingress cert [$certFile] and/or key [$keyFile] file is missing."
41+
log_warn "Create the missing Kubernetes secrets after deployment; use command: kubectl -create secret tls $secretName --namespace $namespace --key=cert_key_file --cert=cert_file"
42+
fi
43+
}
44+
45+
export -f create_ingress_certs
46+
2747
AUTOGENERATE_INGRESS="${AUTOGENERATE_INGRESS:-false}"
2848
AUTOGENERATE_STORAGECLASS="${AUTOGENERATE_STORAGECLASS:-false}"
2949

@@ -57,11 +77,29 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then
5777
exit 1
5878
fi
5979

60-
routing="${ROUTING:-host}"
61-
62-
if [ "$routing" != "host" ]; then
63-
MON_TLS_PATH_INGRESS="true"
80+
ROUTING="${ROUTING:-host}"
81+
82+
if [ "$ROUTING" == "path" ]; then
83+
export MON_TLS_PATH_INGRESS="true"
6484
log_debug "Path ingress requested, setting MON_TLS_PATH_INGRESS to 'true'"
85+
elif [ "$ROUTING" != "host" ] && [ "$ROUTING" != "path" ]; then
86+
log_error "Invalid ROUTING value, valid values are 'host' or 'path'"
87+
exit 1
88+
fi
89+
90+
INGRESS_CERT="${INGRESS_CERT}"
91+
INGRESS_KEY="${INGRESS_KEY}"
92+
if [ "$INGRESS_CERT/$INGRESS_KEY" != "/" ]; then
93+
if [ ! -f "$INGRESS_CERT" ] || [ ! -f "$INGRESS_KEY" ]; then
94+
# Only WARN b/c missing cert doesn't prevent deployment and it can be created afterwards
95+
log_warn "Missing Ingress certificate file; specified Ingress cert [$INGRESS_CERT] and/or key [$INGRESS_KEY] file is missing."
96+
log_warn "You can create the missing Kubernetes secrets after deployment. See Enable TLS for Ingress topic in Help Center documentation."
97+
#unset variable values to prevent further attempted use
98+
unset INGRESS_CERT
99+
unset INGRESS_KEY
100+
else
101+
log_debug "Ingress cert [$INGRESS_CERT] and key [$INGRESS_KEY] files exist."
102+
fi
65103
fi
66104

67105
log_info "Autogeneration of Ingress definitions has been enabled"

logging/bin/deploy_opensearch.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ if [ "$AUTOGENERATE_STORAGECLASS" == "true" ]; then
3939
sc="$storageClass" yq -i '.persistence.storageClass=env(sc)' "$autogeneratedYAMLFile"
4040

4141
else
42-
log_debug "Autogeneration of storageClassReferences NOT enabled"
42+
log_debug "Autogeneration of storageClass References NOT enabled"
4343
fi
4444

4545
AUTOGENERATE_INGRESS="${AUTOGENERATE_INGRESS:-false}"
46+
OPENSEARCH_INGRESS_ENABLE="${OPENSEARCH_INGRESS_ENABLE:-false}"
4647

47-
if [ "$AUTOGENERATE_INGRESS" == "true" ]; then
48-
48+
if [ "$AUTOGENERATE_INGRESS" == "true" ] && [ "$OPENSEARCH_INGRESS_ENABLE"="true" ]; then
4949

5050
if [ ! -f "$autogeneratedYAMLFile" ]; then
5151
log_debug "Creating file [$autogeneratedYAMLFile]"
@@ -54,21 +54,24 @@ if [ "$AUTOGENERATE_INGRESS" == "true" ]; then
5454
log_debug "File [$autogeneratedYAMLFile] already exists"
5555
fi
5656

57-
routing="${ROUTING:-host}"
58-
log_debug "ROUTING [$routing]"
57+
osIngressCert="${OPENSEARCH_INGRESS_CERT}"
58+
osIngressKey="${OPENSEARCH_INGRESS_KEY}"
59+
60+
create_ingress_certs "$LOG_NS" "elasticsearch-ingress-tls-secret" "$osIngressCert" "$osIngressKey"
61+
62+
ROUTING="${ROUTING:-host}"
5963

6064
## tested with sample version: 0.2.1
61-
ingressSampleFile="samples/ingress/${routing}-based-ingress/logging/user-values-opensearch.yaml"
65+
ingressSampleFile="samples/ingress/${ROUTING}-based-ingress/logging/user-values-opensearch.yaml"
6266

6367
#intialized the yaml file w/appropriate ingress sample
6468
yq -i eval-all '. as $item ireduce ({}; . * $item )' "$autogeneratedYAMLFile" "$ingressSampleFile"
6569

66-
67-
OPENSEARCH_INGRESS_ENABLE="${OPENSEARCH_INGRESS_ENABLE:-false}"
70+
6871
OPENSEARCH_FQDN="${OPENSEARCH_FQDN}"
6972
OPENSEARCH_PATH="${OPENSEARCH_PATH:-search}"
7073
if [ -z "$OPENSEARCH_FQDN" ]; then
71-
if [ "$routing" == "host" ]; then
74+
if [ "$ROUTING" == "host" ]; then
7275
OPENSEARCH_FQDN="$OPENSEARCH_PATH.$BASE_DOMAIN"
7376
else
7477
OPENSEARCH_FQDN="$BASE_DOMAIN"
@@ -81,7 +84,7 @@ if [ "$AUTOGENERATE_INGRESS" == "true" ]; then
8184

8285
yq -i '.ingress.enabled=env(OPENSEARCH_INGRESS_ENABLE)' $autogeneratedYAMLFile
8386

84-
if [ "$routing" == "host" ]; then
87+
if [ "$ROUTING" == "host" ]; then
8588
yq -i '.ingress.hosts.[0]=env(OPENSEARCH_FQDN)' $autogeneratedYAMLFile
8689
yq -i '.ingress.tls.[0].hosts.[0]=env(OPENSEARCH_FQDN)' $autogeneratedYAMLFile
8790
else
@@ -95,9 +98,9 @@ if [ "$AUTOGENERATE_INGRESS" == "true" ]; then
9598
printf -v snippet "rewrite (?i)/$OPENSEARCH_PATH/(.*) /\$1 break;\nrewrite (?i)/${OPENSEARCH_PATH}$ / break;" ;
9699
snippet="$snippet" yq -i '.ingress.annotations["nginx.ingress.kubernetes.io/configuration-snippet"]=strenv(snippet)' $autogeneratedYAMLFile
97100

98-
fi
101+
fi
99102
else
100-
log_debug "Autogeneration of ingresss NOT enabled"
103+
log_debug "Autogeneration of ingresss NOT enabled and/or ingress NOT enabled for OpenSearch"
101104
fi
102105

103106

0 commit comments

Comments
 (0)