Skip to content

Commit

Permalink
Fix lint nested if
Browse files Browse the repository at this point in the history
Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>
  • Loading branch information
kfirtoledo committed Jun 25, 2024
1 parent e68c9d8 commit d0b654e
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions pkg/bootstrap/platform/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func K8SConfig(config *Config) ([]byte, error) {
"dataplanePort": dpapi.ListenPort,
}

var k8sConfig, nsConfig, ingressConfig bytes.Buffer
var k8sConfig, nsConfig bytes.Buffer
// ClusterLink namespace
t := template.Must(template.New("").Parse(nsTemplate))
if err := t.Execute(&nsConfig, args); err != nil {
Expand All @@ -343,30 +343,15 @@ func K8SConfig(config *Config) ([]byte, error) {
}

// ClusterLink ingress service
if config.IngressType != "" {
args["ingressPort"] = apis.DefaultExternalPort
args["ingressType"] = config.IngressType
if config.IngressPort != 0 {
if config.IngressType == string(apis.IngressTypeNodePort) {
args["ingressNodePort"] = config.IngressPort
if (config.IngressPort < 30000) || (config.IngressPort > 32767) {
return nil, fmt.Errorf("nodeport number %v is not in the valid range (30000:32767)", config.IngressPort)
}
} else {
args["ingressPort"] = config.IngressPort
}
}

t := template.Must(template.New("").Parse(ingressTemplate))
if err := t.Execute(&ingressConfig, args); err != nil {
return nil, fmt.Errorf("cannot create K8s namespace from template: %w", err)
}
ingressConfig, err := k8SIngressConfig(config)
if err != nil {
return nil, err
}

k8sBytes := nsConfig.Bytes()
k8sBytes = append(k8sBytes, certConfig...)
k8sBytes = append(k8sBytes, k8sConfig.Bytes()...)
k8sBytes = append(k8sBytes, ingressConfig.Bytes()...)
k8sBytes = append(k8sBytes, ingressConfig...)

return k8sBytes, nil
}
Expand Down Expand Up @@ -461,3 +446,38 @@ func K8SEmptyCertificateConfig(config *Config) ([]byte, error) {

return certConfig.Bytes(), nil
}

// k8SIngressConfig returns a kubernetes ingress service.
func k8SIngressConfig(config *Config) ([]byte, error) {
var ingressConfig bytes.Buffer
if config.IngressType == "" {
return ingressConfig.Bytes(), nil
}

args := map[string]interface{}{
"namespace": config.Namespace,
"ingressPort": apis.DefaultExternalPort,
"ingressType": config.IngressType,

"dataplaneAppName": dpapp.Name,
"dataplanePort": dpapi.ListenPort,
}

if config.IngressPort != 0 {
if config.IngressType == string(apis.IngressTypeNodePort) {
args["ingressNodePort"] = config.IngressPort
if (config.IngressPort < 30000) || (config.IngressPort > 32767) {
return nil, fmt.Errorf("nodeport number %v is not in the valid range (30000:32767)", config.IngressPort)
}
} else {
args["ingressPort"] = config.IngressPort
}
}

t := template.Must(template.New("").Parse(ingressTemplate))
if err := t.Execute(&ingressConfig, args); err != nil {
return nil, fmt.Errorf("cannot create K8s namespace from template: %w", err)
}

return ingressConfig.Bytes(), nil
}

0 comments on commit d0b654e

Please sign in to comment.