Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor label names to const strings #948

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/loader/compose/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ import (
"k8s.io/kubernetes/pkg/api"
)

const (
// LabelServiceType defines the type of service to be created
LabelServiceType = "kompose.service.type"
// LabelServiceExpose defines if the service needs to be made accessible from outside the cluster or not
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"
)

// load environment variables from compose file
func loadEnvVars(envars []string) []kobject.EnvVar {
envs := []kobject.EnvVar{}
Expand Down
10 changes: 5 additions & 5 deletions pkg/loader/compose/v1v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,25 @@ func libComposeToKomposeMapping(composeObject *project.Project) (kobject.Kompose
serviceConfig.Labels = make(map[string]string)
for key, value := range composeServiceConfig.Labels {
switch key {
case "kompose.service.type":
case LabelServiceType:
serviceType, err := handleServiceType(value)
if err != nil {
return kobject.KomposeObject{}, errors.Wrap(err, "handleServiceType failed")
}

serviceConfig.ServiceType = serviceType
case "kompose.service.expose":
case LabelServiceExpose:
serviceConfig.ExposeService = strings.ToLower(value)
case "kompose.service.expose.tls-secret":
case LabelServiceExposeTLSSecret:
serviceConfig.ExposeServiceTLS = value
default:
serviceConfig.Labels[key] = value
}
}
if serviceConfig.ExposeService == "" && serviceConfig.ExposeServiceTLS != "" {
return kobject.KomposeObject{}, errors.New("kompose.service.expose.tls-secret was specifed without kompose.service.expose")
return kobject.KomposeObject{}, errors.New("kompose.service.expose.tls-secret was specified without kompose.service.expose")
}
err = checkLabelsPorts(len(serviceConfig.Port), composeServiceConfig.Labels["kompose.service.type"], name)
err = checkLabelsPorts(len(serviceConfig.Port), composeServiceConfig.Labels[LabelServiceType], name)
if err != nil {
return kobject.KomposeObject{}, errors.Wrap(err, "kompose.service.type can't be set if service doesn't expose any ports.")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/loader/compose/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,22 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
// from here for docker-compose. Each loader will have such handler.
for key, value := range composeServiceConfig.Labels {
switch key {
case "kompose.service.type":
case LabelServiceType:
serviceType, err := handleServiceType(value)
if err != nil {
return kobject.KomposeObject{}, errors.Wrap(err, "handleServiceType failed")
}

serviceConfig.ServiceType = serviceType
case "kompose.service.expose":
case LabelServiceExpose:
serviceConfig.ExposeService = strings.ToLower(value)
case "kompose.service.expose.tls-secret":
case LabelServiceExposeTLSSecret:
serviceConfig.ExposeServiceTLS = value
}
}

if serviceConfig.ExposeService == "" && serviceConfig.ExposeServiceTLS != "" {
return kobject.KomposeObject{}, errors.New("kompose.service.expose.tls-secret was specifed without kompose.service.expose")
return kobject.KomposeObject{}, errors.New("kompose.service.expose.tls-secret was specified without kompose.service.expose")
}

// Log if the name will been changed
Expand Down