github.com/verrazzano/verrazzano@v1.7.0/platform-operator/thirdparty/charts/weblogic-operator/templates/_domain-namespaces.tpl (about) 1 # Copyright (c) 2018, 2022, Oracle and/or its affiliates. 2 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 {{- define "operator.domainNamespaces" }} 5 {{- if (eq .domainNamespaceSelectionStrategy "Dedicated") }} 6 {{- $args := include "utils.cloneDictionary" . | fromYaml -}} 7 {{- $key := .Release.Namespace -}} 8 {{- $ignore := set $args "domainNamespace" $key -}} 9 {{- include "operator.operatorRoleBindingNamespace" $args -}} 10 {{- else if eq .domainNamespaceSelectionStrategy "List" }} 11 {{- $args := include "utils.cloneDictionary" . | fromYaml -}} 12 {{- range $key := $args.domainNamespaces -}} 13 {{- $ignore := set $args "domainNamespace" $key -}} 14 {{- include "operator.operatorRoleBindingNamespace" $args -}} 15 {{- end }} 16 {{- else if eq (default "LabelSelector" .domainNamespaceSelectionStrategy) "LabelSelector" }} 17 {{- $args := include "utils.cloneDictionary" . | fromYaml -}} 18 {{- /* 19 Split terms on commas not contained in parentheses. Unfortunately, the regular expression 20 support included with Helm templates does not include lookarounds. 21 */ -}} 22 {{- $working := dict "rejected" (list) "terms" (list $args.domainNamespaceLabelSelector) }} 23 {{- if contains "," $args.domainNamespaceLabelSelector }} 24 {{- $cs := regexSplit "," $args.domainNamespaceLabelSelector -1 }} 25 {{- $ignore := set $working "st" (list) }} 26 {{- $ignore := set $working "item" "" }} 27 {{- range $c := $cs }} 28 {{- if and (contains "(" $c) (not (contains ")" $c)) }} 29 {{- $ignore := set $working "item" (print $working.item $c) }} 30 {{- else if not (eq $working.item "") }} 31 {{- $ignore := set $working "st" (append $working.st (print $working.item "," $c)) }} 32 {{- if contains ")" $c }} 33 {{- $ignore := set $working "item" "" }} 34 {{- end }} 35 {{- else }} 36 {{- $ignore := set $working "st" (append $working.st $c) }} 37 {{- end }} 38 {{- end }} 39 {{- $ignore := set $working "terms" $working.st }} 40 {{- end }} 41 {{- $namespaces := (lookup "v1" "Namespace" "" "").items }} 42 {{- range $t := $working.terms }} 43 {{- $term := trim $t }} 44 {{- range $index, $namespace := $namespaces }} 45 {{- /* 46 Label selector patterns 47 Equality-based: =, ==, != 48 Set-based: x in (a, b), x notin (a, b) 49 Existence: x, !x 50 */ -}} 51 {{- if not $namespace.metadata.labels }} 52 {{- $ignore := set $namespace.metadata "labels" (dict) }} 53 {{- end }} 54 {{- if hasPrefix "!" $term }} 55 {{- if hasKey $namespace.metadata.labels (trimPrefix "!" $term) }} 56 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 57 {{- end }} 58 {{- else if contains "!=" $term }} 59 {{- $split := regexSplit "!=" $term 2 }} 60 {{- $key := nospace (first $split) }} 61 {{- if hasKey $namespace.metadata.labels $key }} 62 {{- if eq (last $split | nospace) (get $namespace.metadata.labels $key) }} 63 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 64 {{- end }} 65 {{- end }} 66 {{- else if contains "==" $term }} 67 {{- $split := regexSplit "==" $term 2 }} 68 {{- $key := nospace (first $split) }} 69 {{- if or (not (hasKey $namespace.metadata.labels $key)) (not (eq (last $split | nospace) (get $namespace.metadata.labels $key))) }} 70 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 71 {{- end }} 72 {{- else if contains "=" $term }} 73 {{- $split := regexSplit "=" $term 2 }} 74 {{- $key := nospace (first $split) }} 75 {{- if or (not (hasKey $namespace.metadata.labels $key)) (not (eq (last $split | nospace) (get $namespace.metadata.labels $key))) }} 76 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 77 {{- end }} 78 {{- else if contains " notin " $term }} 79 {{- $split := regexSplit " notin " $term 2 }} 80 {{- $key := nospace (first $split) }} 81 {{- if hasKey $namespace.metadata.labels $key }} 82 {{- $second := nospace (last $split) }} 83 {{- $parenContents := substr 1 (int (sub (len $second) 1)) $second }} 84 {{- $values := regexSplit "," $parenContents -1 }} 85 {{- range $value := $values }} 86 {{- if eq ($value | nospace) (get $namespace.metadata.labels $key) }} 87 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 88 {{- end }} 89 {{- end }} 90 {{- end }} 91 {{- else if contains " in " $term }} 92 {{- $split := regexSplit " in " $term 2 }} 93 {{- $key := nospace (first $split) }} 94 {{- if not (hasKey $namespace.metadata.labels $key) }} 95 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 96 {{- else }} 97 {{- $second := nospace (last $split) }} 98 {{- $parenContents := substr 1 (int (sub (len $second) 1)) $second }} 99 {{- $values := regexSplit "," $parenContents -1 }} 100 {{- $ignore := set $working "found" false }} 101 {{- range $value := $values }} 102 {{- if eq ($value | nospace) (get $namespace.metadata.labels $key) }} 103 {{- $ignore := set $working "found" true }} 104 {{- end }} 105 {{- end }} 106 {{- if not $working.found }} 107 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 108 {{- end }} 109 {{- end }} 110 {{- else }} 111 {{- if not (hasKey $namespace.metadata.labels $term) }} 112 {{- $ignore := set $working "rejected" (append $working.rejected $namespace.metadata.name) }} 113 {{- end }} 114 {{- end }} 115 {{- end }} 116 {{- end }} 117 {{- range $index, $namespace := $namespaces }} 118 {{- $key := $namespace.metadata.name -}} 119 {{- if not (has $key $working.rejected) }} 120 {{- $ignore := set $args "domainNamespace" $key -}} 121 {{- include "operator.operatorRoleBindingNamespace" $args -}} 122 {{- end }} 123 {{- end }} 124 {{- else if eq .domainNamespaceSelectionStrategy "RegExp" }} 125 {{- $args := include "utils.cloneDictionary" . | fromYaml -}} 126 {{- range $index, $namespace := (lookup "v1" "Namespace" "" "").items }} 127 {{- if regexMatch $args.domainNamespaceRegExp $namespace.metadata.name }} 128 {{- $key := $namespace.metadata.name -}} 129 {{- $ignore := set $args "domainNamespace" $key -}} 130 {{- include "operator.operatorRoleBindingNamespace" $args -}} 131 {{- end }} 132 {{- end }} 133 {{- end }} 134 {{- end }}