Commit d092289c authored by Tim Leers's avatar Tim Leers

Merge branch 'chore-ingress.go' into 'master'

chore: apply lint rules to ingress.go

See merge request uplex/varnish/k8s-ingress!15
parents 6afe6ed7 2fc70d09
......@@ -93,8 +93,8 @@ func (worker *NamespaceWorker) filterVarnishIngSvcs(
}
func (worker *NamespaceWorker) getVarnishSvcForIng(
ing *net_v1.Ingress) (*api_v1.Service, error) {
ing *net_v1.Ingress,
) (*api_v1.Service, error) {
svcs, err := worker.listers.svc.List(varnishIngressSelector)
if err != nil {
return nil, err
......@@ -106,8 +106,7 @@ func (worker *NamespaceWorker) getVarnishSvcForIng(
if varnishSvc, exists := ing.Annotations[varnishSvcKey]; exists {
worker.log.Debugf("Ingress %s/%s has annotation %s:%s",
ing.Namespace, ing.Name, varnishSvcKey, varnishSvc)
targetNs, targetSvc, err :=
cache.SplitMetaNamespaceKey(varnishSvc)
targetNs, targetSvc, err := cache.SplitMetaNamespaceKey(varnishSvc)
if err != nil {
return nil, err
}
......@@ -146,8 +145,8 @@ func (worker *NamespaceWorker) getVarnishSvcForIng(
}
func (worker *NamespaceWorker) getIngsForVarnishSvc(
svc *api_v1.Service) ([]*net_v1.Ingress, error) {
svc *api_v1.Service,
) ([]*net_v1.Ingress, error) {
ings, err := worker.listers.ing.List(labels.Everything())
if err != nil {
return nil, err
......@@ -175,8 +174,7 @@ func (worker *NamespaceWorker) getIngsForVarnishSvc(
namespace = "default"
}
if ingSvc, exists := ing.Annotations[varnishSvcKey]; exists {
targetNs, targetSvc, err :=
cache.SplitMetaNamespaceKey(ingSvc)
targetNs, targetSvc, err := cache.SplitMetaNamespaceKey(ingSvc)
if err != nil {
return nil, err
}
......@@ -203,7 +201,7 @@ func ingMergeError(ings []*net_v1.Ingress) error {
for _, ing := range ings {
if ing.Spec.DefaultBackend != nil {
if ingWdefBackend != nil {
return fmt.Errorf("Default backend configured "+
return fmt.Errorf("default backend configured "+
"in more than one Ingress: %s/%s and "+
"%s/%s", ing.Namespace, ing.Name,
ingWdefBackend.Namespace,
......@@ -213,7 +211,7 @@ func ingMergeError(ings []*net_v1.Ingress) error {
}
for _, rule := range ing.Spec.Rules {
if otherIng, exists := host2ing[rule.Host]; exists {
return fmt.Errorf("Host '%s' named in rules "+
return fmt.Errorf("host '%s' named in rules "+
"for more than one Ingress: %s/%s and "+
"%s/%s", rule.Host, otherIng.Namespace,
otherIng.Name, ing.Namespace, ing.Name)
......@@ -322,9 +320,8 @@ func getVCLProbe(probe *vcr_v1alpha1.ProbeSpec) *vcl.Probe {
Timeout: probe.Timeout,
Interval: probe.Interval,
}
for i, r := range probe.Request {
vclProbe.Request[i] = r
}
copy(vclProbe.Request, probe.Request)
if probe.ExpResponse != nil {
vclProbe.ExpResponse = uint16(*probe.ExpResponse)
}
......@@ -406,8 +403,7 @@ BCfgs:
ShardParam: bcfg.Spec.Director.ShardParam,
}
if bcfg.Spec.Director.Warmup != nil {
vclSvc.Director.Warmup =
float64(*bcfg.Spec.Director.Warmup) / 100.0
vclSvc.Director.Warmup = float64(*bcfg.Spec.Director.Warmup) / 100.0
}
}
// XXX if bcfg.Spec.Probe == nil, look for a HTTP readiness check
......@@ -595,11 +591,11 @@ func (worker *NamespaceWorker) ings2VCLSpec(ings []*net_v1.Ingress) (
for _, rule := range ing.Spec.Rules {
vclRule := vcl.Rule{Host: rule.Host}
vclRule.PathMap = make(map[vcl.PathKey]vcl.Service)
if rule.IngressRuleValue.HTTP == nil {
if rule.HTTP == nil {
vclSpec.Rules = append(vclSpec.Rules, vclRule)
continue
}
for _, path := range rule.IngressRuleValue.HTTP.Paths {
for _, path := range rule.HTTP.Paths {
addrs, extName, extPort, status := worker.
ingBackend2Addrs(namespace,
path.Backend)
......@@ -607,7 +603,7 @@ func (worker *NamespaceWorker) ings2VCLSpec(ings []*net_v1.Ingress) (
return vclSpec, bcfgs, onlds, status
}
if extName == "" &&
(addrs == nil || len(addrs) == 0) {
(len(addrs) == 0) {
panic("len(addrs)==0 namespace=" +
namespace + " IngressBackend=" +
path.Backend.String())
......@@ -660,8 +656,7 @@ func (worker *NamespaceWorker) ings2VCLSpec(ings []*net_v1.Ingress) (
} else {
vclSpec.ExtSvcs[key] = vclSvc
if onload != nil {
onload.Instances =
extOnldInstances
onload.Instances = extOnldInstances
}
}
if bcfg != nil {
......@@ -678,8 +673,8 @@ func (worker *NamespaceWorker) ings2VCLSpec(ings []*net_v1.Ingress) (
}
func configConditions(vclConds []vcl.MatchTerm,
vcfgConds []vcr_v1alpha1.Condition) {
vcfgConds []vcr_v1alpha1.Condition,
) {
if len(vclConds) != len(vcfgConds) {
panic("configConditions: unequal slice lengths")
}
......@@ -688,15 +683,14 @@ func configConditions(vclConds []vcl.MatchTerm,
Comparand: cond.Comparand,
Value: cond.Value,
}
vclMatch.Compare, vclMatch.Negate =
configComparison(cond.Compare)
vclMatch.Compare, vclMatch.Negate = configComparison(cond.Compare)
vclConds[i] = vclMatch
}
}
func (worker *NamespaceWorker) configAuth(spec *vcl.Spec,
vcfg *vcr_v1alpha1.VarnishConfig) error {
vcfg *vcr_v1alpha1.VarnishConfig,
) error {
if len(vcfg.Spec.Auth) == 0 {
worker.log.Infof("No Auth spec found for VarnishConfig %s/%s",
vcfg.Namespace, vcfg.Name)
......@@ -750,8 +744,8 @@ func (worker *NamespaceWorker) configAuth(spec *vcl.Spec,
}
func (worker *NamespaceWorker) configACL(spec *vcl.Spec,
vcfg *vcr_v1alpha1.VarnishConfig) {
vcfg *vcr_v1alpha1.VarnishConfig,
) {
if len(vcfg.Spec.ACLs) == 0 {
worker.log.Infof("No ACL spec found for VarnishConfig %s/%s",
vcfg.Namespace, vcfg.Name)
......@@ -807,8 +801,8 @@ func (worker *NamespaceWorker) configACL(spec *vcl.Spec,
}
func (worker *NamespaceWorker) configRewrites(spec *vcl.Spec,
vcfg *vcr_v1alpha1.VarnishConfig) error {
vcfg *vcr_v1alpha1.VarnishConfig,
) error {
if len(vcfg.Spec.Rewrites) == 0 {
worker.log.Infof("No rewrite spec found for VarnishConfig "+
"%s/%s", vcfg.Namespace, vcfg.Name)
......@@ -866,7 +860,7 @@ func (worker *NamespaceWorker) configRewrites(spec *vcl.Spec,
case vcr_v1alpha1.Delete:
vclRw.Method = vcl.Delete
default:
return fmt.Errorf("Illegal method %s", rw.Method)
return fmt.Errorf("illegal method %s", rw.Method)
}
if rw.Compare == "" {
......@@ -931,8 +925,8 @@ func (worker *NamespaceWorker) configRewrites(spec *vcl.Spec,
}
func (worker *NamespaceWorker) configReqDisps(spec *vcl.Spec,
reqDisps []vcr_v1alpha1.RequestDispSpec, kind, namespace, name string) {
reqDisps []vcr_v1alpha1.RequestDispSpec, kind, namespace, name string,
) {
if len(reqDisps) == 0 {
worker.log.Infof("No request disposition specs found for %s "+
"%s/%s", kind, namespace, name)
......@@ -958,8 +952,7 @@ func (worker *NamespaceWorker) configReqDisps(spec *vcl.Spec,
count := uint(*cond.Count)
vclCond.Count = &count
}
vclCond.Compare, vclCond.Negate =
configComparison(cond.Compare)
vclCond.Compare, vclCond.Negate = configComparison(cond.Compare)
if cond.MatchFlags != nil {
vclCond.MatchFlags = configMatchFlags(
*cond.MatchFlags)
......@@ -993,17 +986,17 @@ func (worker *NamespaceWorker) ings2OffloaderSpec(
if len(tls.Hosts) > 0 {
worker.log.Warnf("Ingress %s/%s: ignoring "+
"Hosts config %v",
ing.ObjectMeta.Namespace,
ing.ObjectMeta.Name, tls.Hosts)
ing.Namespace,
ing.Name, tls.Hosts)
}
if tls.SecretName == "" {
return offldrSpec, fmt.Errorf("Ingress %s/%s: "+
return offldrSpec, fmt.Errorf("ingress %s/%s: "+
"TLS without Secret not supported",
ing.ObjectMeta.Namespace,
ing.ObjectMeta.Name)
ing.Namespace,
ing.Name)
}
secr := haproxy.SecretSpec{
Namespace: ing.ObjectMeta.Namespace,
Namespace: ing.Namespace,
Name: tls.SecretName,
}
offldrSpec.Secrets = append(offldrSpec.Secrets, secr)
......@@ -1117,9 +1110,8 @@ func (worker *NamespaceWorker) updateIngStatus(
updateOpts := metav1.UpdateOptions{}
for _, ing := range ings {
ctx := context.TODO()
ing.Status.LoadBalancer.Ingress =
make([]net_v1.IngressLoadBalancerIngress,
len(ips)+len(hosts))
ing.Status.LoadBalancer.Ingress = make([]net_v1.IngressLoadBalancerIngress,
len(ips)+len(hosts))
copy(ing.Status.LoadBalancer.Ingress, lb)
ingClient := worker.client.NetworkingV1().
Ingresses(ing.Namespace)
......@@ -1156,7 +1148,7 @@ func (worker *NamespaceWorker) updateIngStatus(
func (worker *NamespaceWorker) addOrUpdateIng(
ing *net_v1.Ingress,
) update.Status {
ingKey := ing.ObjectMeta.Namespace + "/" + ing.ObjectMeta.Name
ingKey := ing.Namespace + "/" + ing.Name
worker.log.Infof("Adding or Updating Ingress: %s", ingKey)
// Get the Varnish Service and its Pods
......@@ -1297,8 +1289,7 @@ func (worker *NamespaceWorker) addOrUpdateIng(
return IncompleteIfNotFound(err, "%v", err)
}
offldrSpec.Secrets[sidx].UID = string(s.UID)
offldrSpec.Secrets[sidx].ResourceVersion =
s.ResourceVersion
offldrSpec.Secrets[sidx].ResourceVersion = s.ResourceVersion
}
if status := worker.hController.Update(svcKey, offldAddrs,
offldrSpec); status.IsError() {
......@@ -1408,15 +1399,15 @@ func (worker *NamespaceWorker) isVikingIngress(
return false, err
}
if name == "" {
return false, fmt.Errorf("No IngressClass found with "+
return false, fmt.Errorf("no IngressClass found with "+
"spec.controller: %s", worker.ingClass)
}
return *ing.Spec.IngressClassName == name, nil
}
func (worker *NamespaceWorker) chkAddOrUpdateIng(
ing *net_v1.Ingress) update.Status {
ing *net_v1.Ingress,
) update.Status {
if isViking, err := worker.isVikingIngress(ing); err != nil {
return update.MakeRecoverable(
"Error checking if Ingress %s/%s is to be "+
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment