Skip to content

Commit

Permalink
Refactored UI ingress support
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Oct 28, 2021
1 parent 7d8e016 commit 1b21d00
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 305 deletions.
33 changes: 13 additions & 20 deletions apis/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
v1beta1 "k8s.io/api/networking/v1beta1"
"k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -251,6 +251,18 @@ type Volume struct {

// IngressConfig defines the configuration required to create ingress resource
type IngressConfig struct {
// (Optional) HTTP port (UI) to be exposed via ingress
// +optional
UI *Ingress `json:"ui,omitempty"`

// TODO: Add other ingress config for SQL and GRPC here when implemented
}

// +kubebuilder:object:generate=true
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=true

type Ingress struct {
// (Optional) IngressClassName to be used by ingress resource
// +optional
IngressClassName string `json:"ingressClassName,omitempty"`
Expand All @@ -260,25 +272,6 @@ type IngressConfig struct {
// (Optional) Annotations resource related annotations
// +optional
TLS []v1beta1.IngressTLS `json:"tls,omitempty"`
// (Optional) HTTP port (UI) to be exposed via ingress
// +optional
HTTP *IngressService `json:"http,omitempty"`
// (Optional) GRPC port to be exposed via ingress
// +optional
GRPC *IngressService `json:"grpc,omitempty"`
// (Optional) SQL port to be exposed via ingress
// +optional
SQL *IngressService `json:"sql,omitempty"`
}

// +kubebuilder:object:generate=true
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=true

// IngressService defines the service to be exposed via ingress
type IngressService struct {
// +required
Enabled bool `json:"enabled"`
// host is host to be used for exposing service
// +required
Host string `json:"host"`
Expand Down
23 changes: 4 additions & 19 deletions apis/v1alpha1/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1alpha1

import (
"fmt"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
kerrors "k8s.io/apimachinery/pkg/util/errors"
Expand Down Expand Up @@ -126,26 +125,12 @@ func (r *CrdbCluster) ValidateDelete() error {
}

// ValidateIngress validates the ingress configuration used to create ingress resource
func (r *CrdbCluster) ValidateIngress() []error {
func (r *CrdbCluster) ValidateIngress() (errors []error) {
webhookLog.Info("validate ingress", "name", r.Name)

if r.Spec.Ingress.HTTP == nil && r.Spec.Ingress.SQL == nil && r.Spec.Ingress.GRPC == nil {
return []error{fmt.Errorf("atleast one of http, grpc and sql should be enabled when ingress is set")}
if r.Spec.Ingress.UI != nil && r.Spec.Ingress.UI.Host == "" {
errors = append(errors, fmt.Errorf("host required for UI"))
}

var errors []error

if r.Spec.Ingress.HTTP != nil && r.Spec.Ingress.HTTP.Enabled && r.Spec.Ingress.HTTP.Host == "" {
errors = append(errors, fmt.Errorf("host required for http"))
}

if r.Spec.Ingress.GRPC != nil && r.Spec.Ingress.GRPC.Enabled && r.Spec.Ingress.GRPC.Host == "" {
errors = append(errors, fmt.Errorf("host required for grpc"))
}

if r.Spec.Ingress.SQL != nil && r.Spec.Ingress.SQL.Enabled && r.Spec.Ingress.SQL.Host == "" {
errors = append(errors, fmt.Errorf("host required for sql"))
}

return errors
return
}
33 changes: 3 additions & 30 deletions apis/v1alpha1/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,13 @@ func TestValidateIngress(t *testing.T) {
expected []error
}{
{
name: "ingress config with http host missing",
name: "ingress config with UI host missing",
cluster: &CrdbCluster{
Spec: CrdbClusterSpec{
Ingress: &IngressConfig{HTTP: &IngressService{Enabled: true}},
Ingress: &IngressConfig{UI: &Ingress{IngressClassName: "abc"}},
},
},
expected: []error{fmt.Errorf("host required for http")},
},
{
name: "ingress config with grpc host missing",
cluster: &CrdbCluster{
Spec: CrdbClusterSpec{
Ingress: &IngressConfig{GRPC: &IngressService{Enabled: true}},
},
},
expected: []error{fmt.Errorf("host required for grpc")},
},
{
name: "ingress config with http host missing",
cluster: &CrdbCluster{
Spec: CrdbClusterSpec{
Ingress: &IngressConfig{SQL: &IngressService{Enabled: true}},
},
},
expected: []error{fmt.Errorf("host required for sql")},
},
{
name: "ingress config with nil http, grpc and sql",
cluster: &CrdbCluster{
Spec: CrdbClusterSpec{
Ingress: &IngressConfig{},
},
},
expected: []error{fmt.Errorf("atleast one of http, grpc and sql should be enabled when ingress is set")},
expected: []error{fmt.Errorf("host required for UI")},
},
}

Expand Down
36 changes: 13 additions & 23 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

98 changes: 36 additions & 62 deletions config/crd/bases/crdb.cockroachlabs.com_crdbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -878,76 +878,50 @@ spec:
description: (Optional) Ingress defines the Ingress configuration
used to expose the services using Ingress
properties:
annotations:
additionalProperties:
type: string
description: (Optional) Annotations related to ingress resource
type: object
grpc:
description: (Optional) GRPC port to be exposed via ingress
properties:
enabled:
type: boolean
host:
description: host is
type: string
required:
- enabled
- host
type: object
http:
ui:
description: (Optional) HTTP port (UI) to be exposed via ingress
properties:
enabled:
type: boolean
annotations:
additionalProperties:
type: string
description: (Optional) Annotations related to ingress resource
type: object
host:
description: host is
description: host is host to be used for exposing service
type: string
required:
- enabled
- host
type: object
ingressClassName:
description: (Optional) IngressClassName to be used by ingress
resource
type: string
sql:
description: (Optional) SQL port to be exposed via ingress
properties:
enabled:
type: boolean
host:
description: host is
ingressClassName:
description: (Optional) IngressClassName to be used by ingress
resource
type: string
tls:
description: (Optional) Annotations resource related annotations
items:
description: IngressTLS describes the transport layer security
associated with an Ingress.
properties:
hosts:
description: Hosts are a list of hosts included in the
TLS certificate. The values in this list must match
the name/s used in the tlsSecret. Defaults to the
wildcard host setting for the loadbalancer controller
fulfilling this Ingress, if left unspecified.
items:
type: string
type: array
secretName:
description: SecretName is the name of the secret used
to terminate TLS traffic on port 443. Field is left
optional to allow TLS routing based on SNI hostname
alone. If the SNI host in a listener conflicts with
the "Host" header field used by an IngressRule, the
SNI host is used for termination and value of the
Host header is used for routing.
type: string
type: object
type: array
required:
- enabled
- host
type: object
tls:
description: (Optional) Annotations resource related annotations
items:
description: IngressTLS describes the transport layer security
associated with an Ingress.
properties:
hosts:
description: Hosts are a list of hosts included in the TLS
certificate. The values in this list must match the name/s
used in the tlsSecret. Defaults to the wildcard host setting
for the loadbalancer controller fulfilling this Ingress,
if left unspecified.
items:
type: string
type: array
secretName:
description: SecretName is the name of the secret used to
terminate TLS traffic on port 443. Field is left optional
to allow TLS routing based on SNI hostname alone. If the
SNI host in a listener conflicts with the "Host" header
field used by an IngressRule, the SNI host is used for
termination and value of the Host header is used for routing.
type: string
type: object
type: array
type: object
maxSQLMemory:
description: '(Optional) The maximum in-memory storage capacity available
Expand Down
Loading

0 comments on commit 1b21d00

Please sign in to comment.