Skip to content

Commit

Permalink
feat: Allow clusterip only service (#761)
Browse files Browse the repository at this point in the history
* feat: Allow clusterip only service
* fix: fix question

Signed-off-by: Ashok Pon Kumar <[email protected]>
  • Loading branch information
ashokponkumar authored Feb 9, 2022
1 parent 0fcf07f commit ed5da8c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
2 changes: 0 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ const (
ConfigFile = types.AppNameShort + "config.yaml"
// IgnoreFilename is the name of the file containing the ignore rules and exceptions
IgnoreFilename = "." + types.AppNameShort + "ignore"
// ExposeSelector tag is used to annotate services that are externally exposed
ExposeSelector = types.GroupName + "/service.expose"
// WindowsAnnotation tag is used tag a service to run on windows nodes
WindowsAnnotation = types.GroupName + "/containertype.windows"
// AnnotationLabelValue represents the value when an annotation is valid
Expand Down
1 change: 0 additions & 1 deletion transformer/dockerfilegenerator/java/zuulanalyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (t *ZuulAnalyser) Transform(newArtifacts []transformertypes.Artifact, alrea
if s.Annotations == nil {
s.Annotations = map[string]string{}
}
s.Annotations[common.ExposeSelector] = common.AnnotationLabelValue
}
ir.Services[sn] = s
}
Expand Down
16 changes: 11 additions & 5 deletions transformer/kubernetes/apiresource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (d *Service) createNewResources(ir irtypes.EnhancedIR, supportedKinds []str
ingressEnabled := false
for _, service := range ir.Services {
exposeobjectcreated := false
if service.HasValidAnnotation(common.ExposeSelector) || service.OnlyIngress {
if _, _, _, st := d.getExposeInfo(service); st != "" || service.OnlyIngress {
// Create services depending on whether the service needs to be externally exposed
if common.IsStringPresent(supportedKinds, routeKind) {
//Create Route
Expand Down Expand Up @@ -465,6 +465,10 @@ func (d *Service) getExposeInfo(service irtypes.Service) (servicePorts []core.Se
if serviceType != core.ServiceTypeLoadBalancer {
serviceType = st
}
case core.ServiceTypeClusterIP:
if serviceType != core.ServiceTypeLoadBalancer && serviceType != core.ServiceTypeNodePort {
serviceType = st
}
case "":
continue
}
Expand All @@ -481,16 +485,18 @@ func (d *Service) parseServiceRelPath(path string) (hostPrefix, relPath string,
hostPrefix = ""
const nodeportSuffix = ":N"
const loadBalancerSuffix = ":L"
const clusterIPSuffix = ":C"
const noneSuffix = ":-"
if strings.HasSuffix(relPath, nodeportSuffix) {
serviceType = core.ServiceTypeNodePort
relPath = strings.TrimSuffix(relPath, nodeportSuffix)
}
if strings.HasSuffix(relPath, loadBalancerSuffix) {
} else if strings.HasSuffix(relPath, loadBalancerSuffix) {
serviceType = core.ServiceTypeLoadBalancer
relPath = strings.TrimSuffix(relPath, loadBalancerSuffix)
}
if strings.HasSuffix(relPath, noneSuffix) {
} else if strings.HasSuffix(relPath, clusterIPSuffix) {
serviceType = core.ServiceTypeClusterIP
relPath = strings.TrimSuffix(relPath, clusterIPSuffix)
} else if strings.HasSuffix(relPath, noneSuffix) {
serviceType = ""
relPath = strings.TrimSuffix(relPath, noneSuffix)
}
Expand Down
25 changes: 3 additions & 22 deletions transformer/kubernetes/irpreprocessor/ingresspreprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,22 @@ import (
"github.com/konveyor/move2kube/common"
"github.com/konveyor/move2kube/qaengine"
irtypes "github.com/konveyor/move2kube/types/ir"
"github.com/sirupsen/logrus"
)

// ingressOptimizer optimizes the ingress options of the application
// ingressPreprocessor optimizes the ingress options of the application
type ingressPreprocessor struct {
}

// customize modifies image paths and secret
func (opt *ingressPreprocessor) preprocess(ir irtypes.IR) (irtypes.IR, error) {
if len(ir.Services) == 0 {
logrus.Debugf("No services")
return ir, nil
}

for sn, s := range ir.Services {
tempService := ir.Services[sn]
expose := false
for pfi, pf := range s.ServiceToPodPortForwardings {
if pf.ServicePort.Number == 0 {
continue
}
key := common.ConfigServicesKey + common.Delim + `"` + sn + `"` + common.Delim + `"` + fmt.Sprintf("%d", pf.ServicePort.Number) + `"` + common.Delim + "urlpath"
message := fmt.Sprintf("What URL/path should we expose the service %s's %d port on?", sn, pf.ServicePort.Number)
hints := []string{"Enter :- not expose the service", "Leave out leading / to use first part as subdomain", "Add :N as suffix for NodePort service type", "Add :L for Load Balancer service type"}
message := fmt.Sprintf("What kind of service/ingress to create for %s's %d port?", sn, pf.ServicePort.Number)
hints := []string{"Enter :- to not create service for the port", "For Ingress path, leave out leading / to use first part as subdomain", "Add :N as suffix for NodePort service type", "Add :L for Load Balancer service type", "Add :C for ClusterIP service type"}
exposedServiceRelPath := ""
if pf.ServiceRelPath != "" {
exposedServiceRelPath = pf.ServiceRelPath
Expand All @@ -55,19 +47,8 @@ func (opt *ingressPreprocessor) preprocess(ir irtypes.IR) (irtypes.IR, error) {
}
exposedServiceRelPath = strings.TrimSpace(qaengine.FetchStringAnswer(key, message, hints, exposedServiceRelPath))
pf.ServiceRelPath = exposedServiceRelPath
if exposedServiceRelPath != "" {
expose = true
}
tempService.ServiceToPodPortForwardings[pfi] = pf
}
if tempService.Annotations == nil {
tempService.Annotations = map[string]string{}
}
if expose {
tempService.Annotations[common.ExposeSelector] = common.AnnotationLabelValue
} else {
delete(tempService.Annotations, common.ExposeSelector)
}
ir.Services[sn] = tempService
}
return ir, nil
Expand Down
4 changes: 2 additions & 2 deletions transformer/kubernetes/irpreprocessor/mergepreprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"k8s.io/kubernetes/pkg/apis/networking"
)

//mergePreprocessor implements Optimizer interface
// mergePreprocessor implements preprocess interface
type mergePreprocessor struct {
}

//Optimize uses data from ir containers to fill ir.services
// Preprocesses the port forwardings
func (opt *mergePreprocessor) preprocess(ir irtypes.IR) (irtypes.IR, error) {
for serviceName, service := range ir.Services {
service.Containers = opt.mergeContainers(service.Containers)
Expand Down

0 comments on commit ed5da8c

Please sign in to comment.