Skip to content

Commit

Permalink
Added ingress class annotation (#616)
Browse files Browse the repository at this point in the history
* Added ingress class annotation
  • Loading branch information
retpolanne authored Oct 21, 2019
1 parent 10694c2 commit 5e2524d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ Parameter | Description | Default
`rbac.enabled` | If true, this configure teresa deployment to use rbac, for now it will use the `cluster-admin` role | `false`
`apps.ingress` | If true, teresa will create a ingress when expose the app | `false`
`apps.service_type` | The type used to create the app server | `LoadBalancer`
`apps.ingress_class` | The ingress class to be used | ``
`slugstore.image`| The image to be used for the slugstore | `""`
`slugbuilder.image`| The image to be used for the slugbuilder | `""`

Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,

Expand Down
2 changes: 2 additions & 0 deletions helm/chart/teresa/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ spec:
value: {{ .Values.apps.ingress | quote}}
- name: TERESA_DEPLOY_DEFAULT_SERVICE_TYPE
value: {{ .Values.apps.service_type }}
- name: TERESA_DEPLOY_INGRESS_CLASS
value: {{ .Values.apps.ingress_class }}
volumeMounts:
{{- if .Values.tls.crt }}
- mountPath: /etc/teresa
Expand Down
1 change: 1 addition & 0 deletions helm/chart/teresa/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rbac:
apps:
ingress: false
service_type: LoadBalancer
ingress_class:
slugstore:
image:
slugbuilder:
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Operations interface {
type K8sOperations interface {
CreateOrUpdateDeploy(deploySpec *spec.Deploy) error
CreateOrUpdateCronJob(cronJobSpec *spec.CronJob) error
ExposeDeploy(namespace, name, svcType, portName string, vHosts []string, reserveStaticIp bool, w io.Writer) error
ExposeDeploy(namespace, name, svcType, portName string, vHosts []string, reserveStaticIp bool, ingressClass string, w io.Writer) error
ReplicaSetListByLabel(namespace, label, value string) ([]*ReplicaSetListItem, error)
DeployRollbackToRevision(namespace, name, revision string) error
CreateOrUpdateConfigMap(namespace, name string, data map[string]string) error
Expand Down Expand Up @@ -234,7 +234,7 @@ func (ops *DeployOperations) exposeApp(a *app.App, w io.Writer) error {
}
svcType := ops.serviceType(a)
vHosts := strings.Split(a.VirtualHost, ",")
if err := ops.k8s.ExposeDeploy(a.Name, a.Name, svcType, a.Protocol, vHosts, a.ReserveStaticIp, w); err != nil {
if err := ops.k8s.ExposeDeploy(a.Name, a.Name, svcType, a.Protocol, vHosts, a.ReserveStaticIp, ops.opts.IngressClass, w); err != nil {
return err
}
if a.ReserveStaticIp {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (f *fakeK8sOperations) CreateOrUpdateCronJob(cronJobSpec *spec.CronJob) err
return f.createCronJobReturn
}

func (f *fakeK8sOperations) ExposeDeploy(namespace, name, svcType, portName string, vHosts []string, reserveStaticIp bool, w io.Writer) error {
func (f *fakeK8sOperations) ExposeDeploy(namespace, name, svcType, portName string, vHosts []string, reserveStaticIp bool, ingressClass string, w io.Writer) error {
f.exposeDeployWasCalled = true
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/server/deploy/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Options struct {
BuildLimitMemory string `split_words:"true" default:"1Gi"`
DefaultServiceType string `split_words:"true" default:"LoadBalancer"`
CloudSQLProxyImage string `split_words:"true" default:"gcr.io/cloudsql-docker/gce-proxy:1.11"`
IngressClass string `split_words:"true" default:""`
}

type Service struct {
Expand Down
19 changes: 15 additions & 4 deletions pkg/server/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,25 @@ func (k *Client) HasIngress(namespace, appName string) (bool, error) {
return true, nil
}

func (k *Client) createIngress(namespace, appName string, vHosts []string, reserveStaticIp bool) error {
func (k *Client) createIngress(namespace, appName string, vHosts []string, reserveStaticIp bool, ingressClass string) error {
kc, err := k.buildClient()
if err != nil {
return err
}
igsSpec := ingressSpec(namespace, appName, vHosts, reserveStaticIp)
_, err = kc.ExtensionsV1beta1().Ingresses(namespace).Create(igsSpec)
return errors.Wrap(err, "create ingress failed")
if err != nil {
return errors.Wrap(err, "create ingress failed")
}
if ingressClass != "" {
if err = k.SetIngressAnnotations(
namespace, appName,
map[string]string{"kubernetes.io/ingress.class": ingressClass},
); err != nil {
return errors.Wrap(err, "create ingress failed")
}
}
return nil
}

func (k *Client) UpdateIngress(namespace, name string, vHosts []string, reserveStaticIp bool) error {
Expand Down Expand Up @@ -688,7 +699,7 @@ func (c *Client) IngressAnnotations(namespace, ingName string) (map[string]strin
}

// ExposeDeploy creates a service and/or a ingress if needed
func (k *Client) ExposeDeploy(namespace, appName, svcType, portName string, vHosts []string, reserveStaticIp bool, w io.Writer) error {
func (k *Client) ExposeDeploy(namespace, appName, svcType, portName string, vHosts []string, reserveStaticIp bool, ingressClass string, w io.Writer) error {
hasSrv, err := k.hasService(namespace, appName)
if err != nil {
return err
Expand All @@ -710,7 +721,7 @@ func (k *Client) ExposeDeploy(namespace, appName, svcType, portName string, vHos
}
if !hasIgs {
fmt.Fprintln(w, "Creating ingress")
if err := k.createIngress(namespace, appName, vHosts, reserveStaticIp); err != nil {
if err := k.createIngress(namespace, appName, vHosts, reserveStaticIp, ingressClass); err != nil {
return err
}
}
Expand Down

0 comments on commit 5e2524d

Please sign in to comment.