Skip to content

Commit

Permalink
Add web services handling
Browse files Browse the repository at this point in the history
  • Loading branch information
psav authored and kylape committed Jan 27, 2021
1 parent 934206f commit 8eff2bf
Show file tree
Hide file tree
Showing 35 changed files with 1,221 additions and 297 deletions.
40 changes: 38 additions & 2 deletions apis/cloud.redhat.com/v1alpha1/clowdapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,40 @@ type Job struct {
RestartPolicy v1.RestartPolicy `json:"restartPolicy,omitempty"`
}

// WebDeprecated defines a boolean flag to help distinguish from the newer WebServices
type WebDeprecated bool

// PublicWebService is the definition of the public web service. There can be only
// one public service managed by Clowder.
type PublicWebService struct {

// Enabled describes if Clowder should enable the public service and provide the
// configuration in the cdappconfig.
Enabled bool `json:"enabled,omitempty"`
}

// PrivateWebService is the definition of the private web service. There can be only
// one private service managed by Clowder.
type PrivateWebService struct {
// Enabled describes if Clowder should enable the private service and provide the
// configuration in the cdappconfig.
Enabled bool `json:"enabled,omitempty"`
}

// MetricsWebService is the definition of the metrics web service. This is automatically
// enabled and the configuration here at the moment is included for completeness, as there
// are no configurable options.
type MetricsWebService struct {
}

// WebServices defines the structs for the three exposed web services: public,
// private and metrics.
type WebServices struct {
Public PublicWebService `json:"public,omitempty"`
Private PrivateWebService `json:"private,omitempty"`
Metrics MetricsWebService `json:"metrics,omitempty"`
}

// Deployment defines a service running inside a ClowdApp and will output a deployment resource.
// Only one container per pod is allowed and this is defined in the PodSpec attribute.
type Deployment struct {
Expand All @@ -90,7 +124,9 @@ type Deployment struct {
// If set to true, creates a service on the webPort defined in
// the ClowdEnvironment resource, along with the relevant liveness and
// readiness probes.
Web bool `json:"web,omitempty"`
Web WebDeprecated `json:"web,omitempty"`

WebServices WebServices `json:"webServices,omitempty"`

// PodSpec defines a container running inside a ClowdApp.
PodSpec PodSpec `json:"podSpec,omitempty"`
Expand Down Expand Up @@ -140,7 +176,7 @@ type PodSpec struct {

type PodSpecDeprecated struct {
Name string `json:"name"`
Web bool `json:"web,omitempty"`
Web WebDeprecated `json:"web,omitempty"`
MinReplicas *int32 `json:"minReplicas,omitempty"`
Image string `json:"image,omitempty"`
InitContainers []InitContainer `json:"initContainers,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ type WebMode string
// services and their probes.
type WebConfig struct {
// The port that web services inside ClowdApp pods should be served on.
// If omitted, defaults to 8000.
Port int32 `json:"port,omitempty"`
Port int32 `json:"port"`

// The private port that web services inside a ClowdApp should be served on.
PrivatePort int32 `json:"privatePort,omitempty"`

// An api prefix path that pods will be instructed to use when setting up
// their web server.
Expand All @@ -55,8 +57,7 @@ type MetricsMode string
// metrics services and their probes.
type MetricsConfig struct {
// The port that metrics services inside ClowdApp pods should be served on.
// If omitted, defaults to 9000.
Port int32 `json:"port,omitempty"`
Port int32 `json:"port"`

// A prefix path that pods will be instructed to use when setting up their
// metrics server.
Expand Down
16 changes: 16 additions & 0 deletions bundle/tests/scorecard/kuttl/test-basic-app/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ spec:
value: "env_var_3"
- name: ACG_CONFIG
value: /cdapp/cdappconfig.json
---
apiVersion: v1
kind: Service
metadata:
name: puptoo-processor
namespace: test-basic-app
spec:
selector:
pod: puptoo-processor
ports:
- port: 9000
targetPort: 9000
name: metrics
- port: 8000
targetPort: 8000
name: public
1 change: 1 addition & 0 deletions bundle/tests/scorecard/kuttl/test-basic-app/01-pods.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ spec:
value: override_1
- name: ENV_VAR_3
value: env_var_3
web: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: test-web-services
spec:
finalizers:
- kubernetes
52 changes: 52 additions & 0 deletions bundle/tests/scorecard/kuttl/test-web-services/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: v1
kind: Secret
metadata:
name: puptoo
namespace: test-web-services
labels:
app: puptoo
ownerReferences:
- apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdApp
name: puptoo
type: Opaque
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: puptoo-processor
namespace: test-web-services
spec:
template:
spec:
containers:
- env:
- name: ENV_VAR_1
value: "env_var_1"
- name: ENV_VAR_2
value: "env_var_2"
- name: ACG_CONFIG
value: /cdapp/cdappconfig.json
---
apiVersion: v1
kind: Service
metadata:
name: puptoo-processor
namespace: test-web-services
spec:
selector:
pod: puptoo-processor
ports:
- port: 9000
targetPort: 9000
name: metrics
protocol: TCP
- port: 8000
targetPort: 8000
name: public
protocol: TCP
- port: 10000
targetPort: 10000
name: private
protocol: TCP
58 changes: 58 additions & 0 deletions bundle/tests/scorecard/kuttl/test-web-services/01-pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdEnvironment
metadata:
name: test-web-services
spec:
targetNamespace: test-web-services
providers:
web:
port: 8000
privatePort: 10000
mode: operator
metrics:
port: 9000
mode: operator
path: "/metrics"
kafka:
namespace: kafka
clusterName: my-cluster
mode: none
db:
image: "registry.redhat.io/rhel8/postgresql-12:1-36"
mode: none
logging:
mode: none
objectStore:
mode: none
inMemoryDb:
mode: none
resourceDefaults:
limits:
cpu: 400m
memory: 1024Mi
requests:
cpu: 30m
memory: 512Mi
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdApp
metadata:
name: puptoo
namespace: test-web-services
spec:
envName: test-web-services
deployments:
- name: processor
podSpec:
image: quay.io/psav/clowder-hello
env:
- name: ENV_VAR_1
value: env_var_1
- name: ENV_VAR_2
value: env_var_2
webServices:
private:
enabled: True
public:
enabled: True
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: kudo.dev/v1alpha1
kind: TestStep
commands:
- script: sleep 1
- script: kubectl get secret --namespace=test-web-services puptoo -o json > /tmp/test-web-services
- script: jq -r '.data["cdappconfig.json"]' < /tmp/test-web-services | base64 -d > /tmp/test-web-services-json

- script: jq -r '.publicPort == 8000' -e < /tmp/test-web-services-json
- script: jq -r '.metricsPort == 9000' -e < /tmp/test-web-services-json
- script: jq -r '.privatePort == 10000' -e < /tmp/test-web-services-json
- script: jq -r '.metricsPath == "/metrics"' -e < /tmp/test-web-services-json
10 changes: 10 additions & 0 deletions bundle/tests/scorecard/kuttl/test-web-services/03-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kudo.dev/v1alpha1
kind: TestStep
delete:
- apiVersion: v1
kind: Namespace
name: test-web-services
- apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdEnvironment
name: test-web-services
35 changes: 35 additions & 0 deletions config/crd/bases/cloud.redhat.com_clowdapps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,39 @@ spec:
defined in the ClowdEnvironment resource, along with the relevant
liveness and readiness probes.
type: boolean
webServices:
description: 'WebServices defines the structs for the three exposed
web services: public, private and metrics.'
properties:
metrics:
description: MetricsWebService is the definition of the metrics
web service. This is automatically enabled and the configuration
here at the moment is included for completeness, as there
are no configurable options.
type: object
private:
description: PrivateWebService is the definition of the private
web service. There can be only one private service managed
by Clowder.
properties:
enabled:
description: Enabled describes if Clowder should enable
the private service and provide the configuration in
the cdappconfig.
type: boolean
type: object
public:
description: PublicWebService is the definition of the public
web service. There can be only one public service managed
by Clowder.
properties:
enabled:
description: Enabled describes if Clowder should enable
the public service and provide the configuration in
the cdappconfig.
type: boolean
type: object
type: object
required:
- name
type: object
Expand Down Expand Up @@ -6555,6 +6588,8 @@ spec:
type: object
type: array
web:
description: WebDeprecated defines a boolean flag to help distinguish
from the newer WebServices
type: boolean
required:
- name
Expand Down
11 changes: 9 additions & 2 deletions config/crd/bases/cloud.redhat.com_clowdenvironments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ spec:
type: string
port:
description: The port that metrics services inside ClowdApp
pods should be served on. If omitted, defaults to 9000.
pods should be served on.
format: int32
type: integer
required:
- mode
- port
type: object
objectStore:
description: Defines the Configuration for the Clowder ObjectStore
Expand Down Expand Up @@ -255,11 +256,17 @@ spec:
type: string
port:
description: The port that web services inside ClowdApp pods
should be served on. If omitted, defaults to 8000.
should be served on.
format: int32
type: integer
privatePort:
description: The private port that web services inside a ClowdApp
should be served on.
format: int32
type: integer
required:
- mode
- port
type: object
required:
- inMemoryDb
Expand Down
Loading

0 comments on commit 8eff2bf

Please sign in to comment.