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.nodeport.port | port value (string) |
| 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.storage-class-name | kubernetes supported volume storageClassName |
| 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.
- `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.ingress-class-name` provides the name of ingress class to use with the Kubernetes ingress controller. This requires kompose.service.
For example:
@ -265,6 +267,7 @@ services:
labels:
kompose.service.expose: "counter.example.com,foobar.example.com"
kompose.service.expose.tls-secret: "example-secret"
kompose.service.expose.ingress-class-name: "nginx"
redis:
image: redis:3.0
ports:

View File

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

View File

@ -40,6 +40,8 @@ const (
LabelServiceExpose = "kompose.service.expose"
// LabelServiceExposeTLSSecret provides the name of the TLS secret to use with the Kubernetes ingress controller
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 = "kompose.serviceaccount-name"
// 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)
case LabelServiceExposeTLSSecret:
serviceConfig.ExposeServiceTLS = value
case LabelServiceExposeIngressClassName:
serviceConfig.ExposeServiceIngressClassName = &value
case LabelImagePullSecret:
serviceConfig.ImagePullSecret = value
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")
}
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 {
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
}

View File

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

View File

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

View File

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