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

@ -94,50 +94,51 @@ type ServiceConfigGroup []ServiceConfig
// ServiceConfig holds the basic struct of a container // ServiceConfig holds the basic struct of a container
// which should not introduce any kubernetes specific struct // which should not introduce any kubernetes specific struct
type ServiceConfig struct { type ServiceConfig struct {
Name string Name string
ContainerName string ContainerName string
Image string `compose:"image"` Image string `compose:"image"`
Environment []EnvVar `compose:"environment"` Environment []EnvVar `compose:"environment"`
EnvFile []string `compose:"env_file"` EnvFile []string `compose:"env_file"`
Port []Ports `compose:"ports"` Port []Ports `compose:"ports"`
Command []string `compose:"command"` Command []string `compose:"command"`
WorkingDir string `compose:""` WorkingDir string `compose:""`
DomainName string `compose:"domainname"` DomainName string `compose:"domainname"`
HostName string `compose:"hostname"` HostName string `compose:"hostname"`
Args []string `compose:"args"` Args []string `compose:"args"`
VolList []string `compose:"volumes"` VolList []string `compose:"volumes"`
Network []string `compose:"network"` Network []string `compose:"network"`
Labels map[string]string `compose:"labels"` Labels map[string]string `compose:"labels"`
Annotations map[string]string `compose:""` Annotations map[string]string `compose:""`
CPUSet string `compose:"cpuset"` CPUSet string `compose:"cpuset"`
CPUShares int64 `compose:"cpu_shares"` CPUShares int64 `compose:"cpu_shares"`
CPUQuota int64 `compose:"cpu_quota"` CPUQuota int64 `compose:"cpu_quota"`
CPULimit int64 `compose:""` CPULimit int64 `compose:""`
CPUReservation int64 `compose:""` CPUReservation int64 `compose:""`
CapAdd []string `compose:"cap_add"` CapAdd []string `compose:"cap_add"`
CapDrop []string `compose:"cap_drop"` CapDrop []string `compose:"cap_drop"`
Expose []string `compose:"expose"` Expose []string `compose:"expose"`
ImagePullPolicy string `compose:"kompose.image-pull-policy"` ImagePullPolicy string `compose:"kompose.image-pull-policy"`
Pid string `compose:"pid"` Pid string `compose:"pid"`
Privileged bool `compose:"privileged"` Privileged bool `compose:"privileged"`
Restart string `compose:"restart"` Restart string `compose:"restart"`
User string `compose:"user"` User string `compose:"user"`
VolumesFrom []string `compose:"volumes_from"` VolumesFrom []string `compose:"volumes_from"`
ServiceType string `compose:"kompose.service.type"` ServiceType string `compose:"kompose.service.type"`
NodePortPort int32 `compose:"kompose.service.nodeport.port"` NodePortPort int32 `compose:"kompose.service.nodeport.port"`
StopGracePeriod string `compose:"stop_grace_period"` StopGracePeriod string `compose:"stop_grace_period"`
Build string `compose:"build"` Build string `compose:"build"`
BuildArgs map[string]*string `compose:"build-args"` BuildArgs map[string]*string `compose:"build-args"`
ExposeService string `compose:"kompose.service.expose"` ExposeService string `compose:"kompose.service.expose"`
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"`
ImagePullSecret string `compose:"kompose.image-pull-secret"` ExposeServiceIngressClassName *string `compose:"kompose.service.expose.ingress-class-name"`
Stdin bool `compose:"stdin_open"` ImagePullSecret string `compose:"kompose.image-pull-secret"`
Tty bool `compose:"tty"` Stdin bool `compose:"stdin_open"`
MemLimit yaml.MemStringorInt `compose:"mem_limit"` Tty bool `compose:"tty"`
MemReservation yaml.MemStringorInt `compose:""` MemLimit yaml.MemStringorInt `compose:"mem_limit"`
DeployMode string `compose:""` MemReservation yaml.MemStringorInt `compose:""`
DeployMode string `compose:""`
// DeployLabels mapping to kubernetes labels // DeployLabels mapping to kubernetes labels
DeployLabels map[string]string `compose:""` DeployLabels map[string]string `compose:""`
DeployUpdateConfig dockerCliTypes.UpdateConfig `compose:""` DeployUpdateConfig dockerCliTypes.UpdateConfig `compose:""`

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"
} }
}, },