Skip to content

Commit

Permalink
finish with DEV-22200
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimss committed Mar 13, 2024
1 parent 6e3e83c commit b18a196
Show file tree
Hide file tree
Showing 42 changed files with 155 additions and 47 deletions.
12 changes: 9 additions & 3 deletions api/v1/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,16 @@ type Proxy struct {
NoProxy []string `json:"noProxy,omitempty"`
}

type ClusterDomainPrefix struct {
Enabled bool `json:"enabled,omitempty"`
Prefix string `json:"prefix,omitempty"`
}

type Networking struct {
Ingress Ingress `json:"ingress,omitempty"`
HTTPS HTTPS `json:"https,omitempty"`
Proxy Proxy `json:"proxy,omitempty"`
Ingress Ingress `json:"ingress,omitempty"`
HTTPS HTTPS `json:"https,omitempty"`
Proxy Proxy `json:"proxy,omitempty"`
ClusterDomainPrefix ClusterDomainPrefix `json:"clusterDomainPrefix,omitempty"`
}

type SSO struct {
Expand Down
5 changes: 3 additions & 2 deletions api/v1/appdefaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,9 @@ var networkingDefault = Networking{
IstioIngressSelectorValue: "ingressgateway",
OcpSecureRoutes: false,
},
HTTPS: HTTPS{Enabled: false},
Proxy: Proxy{Enabled: false, ConfigRef: "cp-proxy"},
HTTPS: HTTPS{Enabled: false},
Proxy: Proxy{Enabled: false, ConfigRef: "cp-proxy"},
ClusterDomainPrefix: ClusterDomainPrefix{Enabled: false},
}

var ssoDefault = SSO{
Expand Down
16 changes: 16 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions charts/cnvrg-mlops-idc/crds/mlops.cnvrg.io_cnvrgapps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,13 @@ spec:
type: object
networking:
properties:
clusterDomainPrefix:
properties:
enabled:
type: boolean
prefix:
type: string
type: object
https:
properties:
cert:
Expand Down
3 changes: 3 additions & 0 deletions charts/cnvrg-mlops-idc/templates/cap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ spec:
httpProxy: {{ toJson .Values.networking.proxy.httpProxy }}
httpsProxy: {{ toJson .Values.networking.proxy.httpsProxy}}
noProxy: {{ toJson .Values.networking.proxy.noProxy}}
clusterDomainPrefix:
enabled: {{ .Values.networking.clusterDomainPrefix.enabled }}
prefix: {{ .Values.networking.clusterDomainPrefix.prefix }}
sso:
enabled: {{.Values.sso.enabled}}
version: {{.Values.sso.version}}
Expand Down
2 changes: 1 addition & 1 deletion charts/cnvrg-mlops-idc/templates/operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ spec:
- "3"
- --namespace
- {{.Release.Namespace}}
image: "{{.Values.imageHub}}/cnvrg-operator:v5.0.1.snp"
image: "{{.Values.imageHub}}/cnvrg-operator:5.0.0-DEV-22200-definable-application-host-names-943"
imagePullPolicy: Always
name: cnvrg-operator
resources:
Expand Down
3 changes: 3 additions & 0 deletions charts/cnvrg-mlops-idc/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ networking:
httpProxy: []
httpsProxy: []
noProxy: []
clusterDomainPrefix:
enabled: true
prefix: ""
sso:
enabled: false
version: v3
Expand Down
7 changes: 7 additions & 0 deletions charts/cnvrg-mlops/crds/mlops.cnvrg.io_cnvrgapps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,13 @@ spec:
type: object
networking:
properties:
clusterDomainPrefix:
properties:
enabled:
type: boolean
prefix:
type: string
type: object
https:
properties:
cert:
Expand Down
7 changes: 7 additions & 0 deletions charts/cnvrg-operator/crds/mlops.cnvrg.io_cnvrgapps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,13 @@ spec:
type: object
networking:
properties:
clusterDomainPrefix:
properties:
enabled:
type: boolean
prefix:
type: string
type: object
https:
properties:
cert:
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/mlops.cnvrg.io_cnvrgapps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,13 @@ spec:
type: object
networking:
properties:
clusterDomainPrefix:
properties:
enabled:
type: boolean
prefix:
type: string
type: object
https:
properties:
cert:
Expand Down
30 changes: 28 additions & 2 deletions controllers/app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
mathrand "math/rand"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
"sort"
Expand Down Expand Up @@ -64,6 +65,9 @@ func getTlsCert(app *mlopsv1.CnvrgApp, clientset client.Client) (cert string, ke

func CalculateAndApplyAppDefaults(app *mlopsv1.CnvrgApp, defaultSpec *mlopsv1.CnvrgAppSpec, clientset client.Client) error {

// set cluster domain prefix if enabled
setClusterDomainPrefix(app, defaultSpec)

// set default heap size for ES if not set by user
if strings.Contains(app.Spec.Dbs.Es.Requests.Memory, "Gi") && app.Spec.Dbs.Es.JavaOpts == "" {
requestMem := strings.TrimSuffix(app.Spec.Dbs.Es.Requests.Memory, "Gi")
Expand Down Expand Up @@ -131,7 +135,11 @@ func CalculateAndApplyAppDefaults(app *mlopsv1.CnvrgApp, defaultSpec *mlopsv1.Cn
scheme = "https"
}
if app.Spec.SSO.Central.PublicUrl == "" {
defaultSpec.SSO.Central.PublicUrl = fmt.Sprintf("%s://%s.%s", scheme, defaultSpec.SSO.Central.SvcName, app.Spec.ClusterDomain)
defaultSpec.SSO.Central.PublicUrl = fmt.Sprintf("%s://%s%s.%s",
scheme,
defaultSpec.SSO.Central.SvcName,
defaultSpec.Networking.ClusterDomainPrefix.Prefix,
app.Spec.ClusterDomain)
}
if app.Spec.SSO.Proxy.Address == "" {
defaultSpec.SSO.Proxy.Address = fmt.Sprintf("%s.%s.svc.%s",
Expand All @@ -142,8 +150,9 @@ func CalculateAndApplyAppDefaults(app *mlopsv1.CnvrgApp, defaultSpec *mlopsv1.Cn
}
if app.Spec.SSO.Central.JwksURL == "" {

defaultSpec.SSO.Central.JwksURL = fmt.Sprintf("%s://%s.%s/v1/%s/.well-known/jwks.json?client_id", scheme,
defaultSpec.SSO.Central.JwksURL = fmt.Sprintf("%s://%s%s.%s/v1/%s/.well-known/jwks.json?client_id", scheme,
defaultSpec.SSO.Jwks.SvcName,
defaultSpec.Networking.ClusterDomainPrefix.Prefix,
app.Spec.ClusterDomain,
strings.Split(app.Spec.ClusterDomain, ".")[0],
)
Expand All @@ -165,9 +174,26 @@ func CalculateAndApplyAppDefaults(app *mlopsv1.CnvrgApp, defaultSpec *mlopsv1.Cn
return nil
}

func setClusterDomainPrefix(app *mlopsv1.CnvrgApp, defaultSpec *mlopsv1.CnvrgAppSpec) {
if app.Spec.Networking.ClusterDomainPrefix.Enabled && app.Spec.Networking.ClusterDomainPrefix.Prefix == "" {
defaultSpec.Networking.ClusterDomainPrefix.Prefix = fmt.Sprintf("-%s", RandomString(5))
}
}

func labelsMapToList(labels map[string]string) (labelList []string) {
for labelName, _ := range labels {
labelList = append(labelList, labelName)
}
return labelList
}

func RandomString(length int) string {
var output strings.Builder
charSet := "abcdefghijklmnopqrstuvwxyz0123456789"
for i := 0; i < length; i++ {
random := mathrand.Intn(len(charSet))
randomChar := charSet[random]
output.WriteString(string(randomChar))
}
return output.String()
}
1 change: 1 addition & 0 deletions pkg/app/controlplane/tmpl/conf/cm/config-networking.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data:
DEFAULT_COMPUTE_CLUSTER_DOMAIN: "{{ defaultComputeClusterDomain .}}"
DEFAULT_COMPUTE_CLUSTER_HTTPS: "{{ .Spec.Networking.HTTPS.Enabled }}"
CNVRG_CLUSTER_INTERNAL_DOMAIN: "{{ .Spec.ClusterInternalDomain }}"
CNVRG_CLUSTER_DOMAIN_PREFIX: "{{ .Spec.Networking.ClusterDomainPrefix.Prefix }}"
HYPER_SERVER_URL: "{{ hyperServerUrl .}}"
HYPER_SERVER_PORT: "{{ .Spec.ControlPlane.Hyper.Port }}"
ROUTE_BY_ISTIO: "{{ routeBy . "ISTIO" }}"
Expand Down
7 changes: 7 additions & 0 deletions pkg/app/controlplane/tmpl/crds/mlops.cnvrg.io_cnvrgapps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,13 @@ spec:
type: object
networking:
properties:
clusterDomainPrefix:
properties:
enabled:
type: boolean
prefix:
type: string
type: object
https:
properties:
cert:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ metadata:
mlops.cnvrg.io/default-loader: "true"
mlops.cnvrg.io/own: "false"
mlops.cnvrg.io/updatable: "true"
mlops.cnvrg.io/default-loader: "true"
mlops.cnvrg.io/own: "false"
mlops.cnvrg.io/updatable: "true"
mlops.cnvrg.io/default-loader: "true"
mlops.cnvrg.io/own: "false"
mlops.cnvrg.io/updatable: "true"
mlops.cnvrg.io/default-loader: "true"
mlops.cnvrg.io/own: "false"
mlops.cnvrg.io/updatable: "true"
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: cnvrgthirdparties.mlops.cnvrg.io
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/controlplane/tmpl/webapp/ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ spec:
{{- if and ( isTrue .Spec.Networking.HTTPS.Enabled ) (ne .Spec.Networking.HTTPS.CertSecret "") }}
tls:
- hosts:
- {{ .Spec.ControlPlane.WebApp.SvcName}}.{{ .Spec.ClusterDomain }}
- {{ .Spec.ControlPlane.WebApp.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}
secretName: {{ .Spec.Networking.HTTPS.CertSecret }}
{{- end }}
rules:
- host: "{{.Spec.ControlPlane.WebApp.SvcName}}.{{ .Spec.ClusterDomain }}"
- host: "{{.Spec.ControlPlane.WebApp.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
http:
paths:
- path: /
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/controlplane/tmpl/webapp/route.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
{{$k}}: "{{$v}}"
{{- end }}
spec:
host: "{{ .Spec.ControlPlane.WebApp.SvcName }}.{{ .Spec.ClusterDomain }}"
host: "{{ .Spec.ControlPlane.WebApp.SvcName }}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
port:
{{- if isTrue .Spec.SSO.Enabled }}
targetPort: 8888
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/controlplane/tmpl/webapp/vs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
{{- end }}
spec:
hosts:
- "{{.Spec.ControlPlane.WebApp.SvcName}}.{{ .Spec.ClusterDomain }}"
- "{{.Spec.ControlPlane.WebApp.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
gateways:
- {{ .Spec.Networking.Ingress.IstioGwName}}
http:
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/dbs/tmpl/es/elastalert/ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ spec:
{{- if and ( isTrue .Spec.Networking.HTTPS.Enabled ) (ne .Spec.Networking.HTTPS.CertSecret "") }}
tls:
- hosts:
- {{ .Spec.Dbs.Es.Elastalert.SvcName }}.{{ .Spec.ClusterDomain }}
- {{ .Spec.Dbs.Es.Elastalert.SvcName }}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}
secretName: {{ .Spec.Networking.HTTPS.CertSecret }}
{{- end }}
rules:
- host: "{{.Spec.Dbs.Es.Elastalert.SvcName}}.{{ .Spec.ClusterDomain }}"
- host: "{{.Spec.Dbs.Es.Elastalert.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
http:
paths:
- path: /
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/dbs/tmpl/es/elastalert/route.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ metadata:
{{$k}}: "{{$v}}"
{{- end }}
spec:
host: "{{ .Spec.Dbs.Es.Elastalert.SvcName }}.{{ .Spec.ClusterDomain }}"
host: "{{ .Spec.Dbs.Es.Elastalert.SvcName }}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
port:
targetPort: {{ .Spec.Dbs.Es.Elastalert.Port }}
to:
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/dbs/tmpl/es/elastalert/vs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metadata:
{{- end }}
spec:
hosts:
- "{{.Spec.Dbs.Es.Elastalert.SvcName}}.{{ .Spec.ClusterDomain }}"
- "{{.Spec.Dbs.Es.Elastalert.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
gateways:
- {{ .Spec.Networking.Ingress.IstioGwName}}
http:
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/dbs/tmpl/es/elastic/ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ spec:
{{- if and ( isTrue .Spec.Networking.HTTPS.Enabled ) (ne .Spec.Networking.HTTPS.CertSecret "") }}
tls:
- hosts:
- {{ .Spec.Dbs.Es.SvcName}}.{{ .Spec.ClusterDomain }}
- {{ .Spec.Dbs.Es.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}
secretName: {{ .Spec.Networking.HTTPS.CertSecret }}
{{- end }}
rules:
- host: "{{.Spec.Dbs.Es.SvcName}}.{{ .Spec.ClusterDomain }}"
- host: "{{.Spec.Dbs.Es.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
http:
paths:
- path: /
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/dbs/tmpl/es/elastic/route.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ metadata:
{{$k}}: "{{$v}}"
{{- end }}
spec:
host: "{{ .Spec.Dbs.Es.SvcName }}.{{ .Spec.ClusterDomain }}"
host: "{{ .Spec.Dbs.Es.SvcName }}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
port:
targetPort: {{ .Spec.Dbs.Es.Port }}
to:
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/dbs/tmpl/es/elastic/vs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metadata:
{{- end }}
spec:
hosts:
- "{{.Spec.Dbs.Es.SvcName}}.{{ .Spec.ClusterDomain }}"
- "{{.Spec.Dbs.Es.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
gateways:
- {{ .Spec.Networking.Ingress.IstioGwName }}
http:
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/dbs/tmpl/es/kibana/ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ spec:
{{- if and ( isTrue .Spec.Networking.HTTPS.Enabled ) (ne .Spec.Networking.HTTPS.CertSecret "") }}
tls:
- hosts:
- {{.Spec.Dbs.Es.Kibana.SvcName}}.{{ .Spec.ClusterDomain }}
- {{.Spec.Dbs.Es.Kibana.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}
secretName: {{ .Spec.Networking.HTTPS.CertSecret }}
{{- end }}
rules:
- host: "{{.Spec.Dbs.Es.Kibana.SvcName}}.{{ .Spec.ClusterDomain }}"
- host: "{{.Spec.Dbs.Es.Kibana.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
http:
paths:
- path: /
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/dbs/tmpl/es/kibana/route.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
{{$k}}: "{{$v}}"
{{- end }}
spec:
host: "{{ .Spec.Dbs.Es.Kibana.SvcName }}.{{ .Spec.ClusterDomain }}"
host: "{{ .Spec.Dbs.Es.Kibana.SvcName }}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
port:
{{- if isTrue .Spec.SSO.Enabled }}
targetPort: 8888
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/dbs/tmpl/es/kibana/vs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
{{- end }}
spec:
hosts:
- "{{.Spec.Dbs.Es.Kibana.SvcName}}.{{ .Spec.ClusterDomain }}"
- "{{.Spec.Dbs.Es.Kibana.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
gateways:
- {{ .Spec.Networking.Ingress.IstioGwName}}
http:
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/dbs/tmpl/minio/ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ spec:
{{- if and ( isTrue .Spec.Networking.HTTPS.Enabled ) (ne .Spec.Networking.HTTPS.CertSecret "") }}
tls:
- hosts:
- {{ .Spec.Dbs.Minio.SvcName}}.{{ .Spec.ClusterDomain }}
- {{ .Spec.Dbs.Minio.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}
secretName: {{ .Spec.Networking.HTTPS.CertSecret }}
{{- end }}
rules:
- host: "{{.Spec.Dbs.Minio.SvcName}}.{{ .Spec.ClusterDomain }}"
- host: "{{.Spec.Dbs.Minio.SvcName}}{{.Spec.Networking.ClusterDomainPrefix.Prefix}}.{{ .Spec.ClusterDomain }}"
http:
paths:
- path: /
Expand Down
Loading

0 comments on commit b18a196

Please sign in to comment.