forked from LaconicNetwork/kompose
Add kompose.service.expose.ingress-class-name (#1486)
Signed-off-by: Sergey Shevchenko <shevchenko@simple.life>
This commit is contained in:
parent
8e94728ddb
commit
98578640c0
@ -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:
|
||||
|
||||
@ -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:""`
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
1
script/test/fixtures/expose/compose.yaml
vendored
1
script/test/fixtures/expose/compose.yaml
vendored
@ -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:
|
||||
|
||||
5
script/test/fixtures/expose/output-k8s.json
vendored
5
script/test/fixtures/expose/output-k8s.json
vendored
@ -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": [
|
||||
|
||||
2
script/test/fixtures/expose/output-ocp.json
vendored
2
script/test/fixtures/expose/output-ocp.json
vendored
@ -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"
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user