Add kompose.service.expose.ingress-class-name (#1486)

Signed-off-by: Sergey Shevchenko <shevchenko@simple.life>
This commit is contained in:
Sergey Shevchenko 2022-03-15 18:51:00 +04:00 committed by GitHub
parent 8e94728ddb
commit 98578640c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 44 deletions

View File

@ -182,6 +182,7 @@ The currently supported options are:
| kompose.service.expose | true / hostnames (separated by comma) | | kompose.service.expose | true / hostnames (separated by comma) |
| kompose.service.nodeport.port | port value (string) | | kompose.service.nodeport.port | port value (string) |
| kompose.service.expose.tls-secret | secret name | | kompose.service.expose.tls-secret | secret name |
| kompose.service.expose.ingress-class-name | ingress class name |
| kompose.volume.size | kubernetes supported volume size | | kompose.volume.size | kubernetes supported volume size |
| kompose.volume.storage-class-name | kubernetes supported volume storageClassName | | kompose.volume.storage-class-name | kubernetes supported volume storageClassName |
| kompose.volume.type | use k8s volume type, eg "configMap", "persistentVolumeClaim", "emptyDir", "hostPath" | | kompose.volume.type | use k8s volume type, eg "configMap", "persistentVolumeClaim", "emptyDir", "hostPath" |
@ -250,6 +251,7 @@ services:
- For the OpenShift provider, a route is created. - For the OpenShift provider, a route is created.
- `kompose.service.nodeport.port` defines the port value when service type is `nodeport`, this label should only be set when the service only contains 1 port. Usually kubernetes define a port range for node port values, kompose will not validate this. - `kompose.service.nodeport.port` defines the port value when service type is `nodeport`, this label should only be set when the service only contains 1 port. Usually kubernetes define a port range for node port values, kompose will not validate this.
- `kompose.service.expose.tls-secret` provides the name of the TLS secret to use with the Kubernetes ingress controller. This requires kompose.service.expose to be set. - `kompose.service.expose.tls-secret` provides the name of the TLS secret to use with the Kubernetes ingress controller. This requires kompose.service.expose to be set.
- `kompose.service.expose.ingress-class-name` provides the name of ingress class to use with the Kubernetes ingress controller. This requires kompose.service.
For example: For example:
@ -265,6 +267,7 @@ services:
labels: labels:
kompose.service.expose: "counter.example.com,foobar.example.com" kompose.service.expose: "counter.example.com,foobar.example.com"
kompose.service.expose.tls-secret: "example-secret" kompose.service.expose.tls-secret: "example-secret"
kompose.service.expose.ingress-class-name: "nginx"
redis: redis:
image: redis:3.0 image: redis:3.0
ports: ports:

View File

@ -132,6 +132,7 @@ type ServiceConfig struct {
ExposeServicePath string `compose:"kompose.service.expose.path"` ExposeServicePath string `compose:"kompose.service.expose.path"`
BuildLabels map[string]string `compose:"build-labels"` BuildLabels map[string]string `compose:"build-labels"`
ExposeServiceTLS string `compose:"kompose.service.expose.tls-secret"` ExposeServiceTLS string `compose:"kompose.service.expose.tls-secret"`
ExposeServiceIngressClassName *string `compose:"kompose.service.expose.ingress-class-name"`
ImagePullSecret string `compose:"kompose.image-pull-secret"` ImagePullSecret string `compose:"kompose.image-pull-secret"`
Stdin bool `compose:"stdin_open"` Stdin bool `compose:"stdin_open"`
Tty bool `compose:"tty"` Tty bool `compose:"tty"`

View File

@ -40,6 +40,8 @@ const (
LabelServiceExpose = "kompose.service.expose" LabelServiceExpose = "kompose.service.expose"
// LabelServiceExposeTLSSecret provides the name of the TLS secret to use with the Kubernetes ingress controller // LabelServiceExposeTLSSecret provides the name of the TLS secret to use with the Kubernetes ingress controller
LabelServiceExposeTLSSecret = "kompose.service.expose.tls-secret" LabelServiceExposeTLSSecret = "kompose.service.expose.tls-secret"
// LabelServiceExposeIngressClassName provides the name of ingress class to use with the Kubernetes ingress controller
LabelServiceExposeIngressClassName = "kompose.service.expose.ingress-class-name"
// LabelServiceAccountName defines the service account name to provide the credential info of the pod. // LabelServiceAccountName defines the service account name to provide the credential info of the pod.
LabelServiceAccountName = "kompose.serviceaccount-name" LabelServiceAccountName = "kompose.serviceaccount-name"
// LabelControllerType defines the type of controller to be created // LabelControllerType defines the type of controller to be created

View File

@ -658,6 +658,8 @@ func parseKomposeLabels(labels map[string]string, serviceConfig *kobject.Service
serviceConfig.NodePortPort = cast.ToInt32(value) serviceConfig.NodePortPort = cast.ToInt32(value)
case LabelServiceExposeTLSSecret: case LabelServiceExposeTLSSecret:
serviceConfig.ExposeServiceTLS = value serviceConfig.ExposeServiceTLS = value
case LabelServiceExposeIngressClassName:
serviceConfig.ExposeServiceIngressClassName = &value
case LabelImagePullSecret: case LabelImagePullSecret:
serviceConfig.ImagePullSecret = value serviceConfig.ImagePullSecret = value
case LabelImagePullPolicy: case LabelImagePullPolicy:
@ -671,6 +673,10 @@ func parseKomposeLabels(labels map[string]string, serviceConfig *kobject.Service
return errors.New("kompose.service.expose.tls-secret was specified without kompose.service.expose") return errors.New("kompose.service.expose.tls-secret was specified without kompose.service.expose")
} }
if serviceConfig.ExposeService == "" && serviceConfig.ExposeServiceIngressClassName != nil {
return errors.New("kompose.service.expose.ingress-class-name was specified without kompose.service.expose")
}
if serviceConfig.ServiceType != string(api.ServiceTypeNodePort) && serviceConfig.NodePortPort != 0 { if serviceConfig.ServiceType != string(api.ServiceTypeNodePort) && serviceConfig.NodePortPort != 0 {
return errors.New("kompose.service.type must be nodeport when assign node port value") return errors.New("kompose.service.type must be nodeport when assign node port value")
} }

View File

@ -525,6 +525,10 @@ func (k *Kubernetes) initIngress(name string, service kobject.ServiceConfig, por
} }
} }
if service.ExposeServiceIngressClassName != nil {
ingress.Spec.IngressClassName = service.ExposeServiceIngressClassName
}
return ingress return ingress
} }

View File

@ -7,6 +7,7 @@ web:
labels: labels:
kompose.service.expose: "batman.example.com/dev,batwoman.example.com" kompose.service.expose: "batman.example.com/dev,batwoman.example.com"
kompose.service.expose.tls-secret: "test-secret" kompose.service.expose.tls-secret: "test-secret"
kompose.service.expose.ingress-class-name: "nginx"
redis: redis:
image: redis:3.0 image: redis:3.0
ports: ports:

View File

@ -40,6 +40,7 @@
}, },
"annotations": { "annotations": {
"kompose.service.expose": "batman.example.com/dev,batwoman.example.com", "kompose.service.expose": "batman.example.com/dev,batwoman.example.com",
"kompose.service.expose.ingress-class-name": "nginx",
"kompose.service.expose.tls-secret": "test-secret" "kompose.service.expose.tls-secret": "test-secret"
} }
}, },
@ -114,6 +115,7 @@
}, },
"annotations": { "annotations": {
"kompose.service.expose": "batman.example.com/dev,batwoman.example.com", "kompose.service.expose": "batman.example.com/dev,batwoman.example.com",
"kompose.service.expose.ingress-class-name": "nginx",
"kompose.service.expose.tls-secret": "test-secret" "kompose.service.expose.tls-secret": "test-secret"
} }
}, },
@ -132,6 +134,7 @@
}, },
"annotations": { "annotations": {
"kompose.service.expose": "batman.example.com/dev,batwoman.example.com", "kompose.service.expose": "batman.example.com/dev,batwoman.example.com",
"kompose.service.expose.ingress-class-name": "nginx",
"kompose.service.expose.tls-secret": "test-secret" "kompose.service.expose.tls-secret": "test-secret"
} }
}, },
@ -166,10 +169,12 @@
}, },
"annotations": { "annotations": {
"kompose.service.expose": "batman.example.com/dev,batwoman.example.com", "kompose.service.expose": "batman.example.com/dev,batwoman.example.com",
"kompose.service.expose.ingress-class-name": "nginx",
"kompose.service.expose.tls-secret": "test-secret" "kompose.service.expose.tls-secret": "test-secret"
} }
}, },
"spec": { "spec": {
"ingressClassName": "nginx",
"tls": [ "tls": [
{ {
"hosts": [ "hosts": [

View File

@ -40,6 +40,7 @@
}, },
"annotations": { "annotations": {
"kompose.service.expose": "batman.example.com/dev,batwoman.example.com", "kompose.service.expose": "batman.example.com/dev,batwoman.example.com",
"kompose.service.expose.ingress-class-name": "nginx",
"kompose.service.expose.tls-secret": "test-secret" "kompose.service.expose.tls-secret": "test-secret"
} }
}, },
@ -174,6 +175,7 @@
}, },
"annotations": { "annotations": {
"kompose.service.expose": "batman.example.com/dev,batwoman.example.com", "kompose.service.expose": "batman.example.com/dev,batwoman.example.com",
"kompose.service.expose.ingress-class-name": "nginx",
"kompose.service.expose.tls-secret": "test-secret" "kompose.service.expose.tls-secret": "test-secret"
} }
}, },