Skip to content
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
80 changes: 40 additions & 40 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ func (cnf *Configurator) deleteIngressMetricsLabels(key string) {
func (cnf *Configurator) AddOrUpdateIngress(ingEx *IngressEx) (Warnings, error) {
warnings, err := cnf.addOrUpdateIngress(ingEx)
if err != nil {
return warnings, fmt.Errorf("Error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
return warnings, fmt.Errorf("error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return warnings, fmt.Errorf("Error reloading NGINX for %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
return warnings, fmt.Errorf("error reloading NGINX for %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
}

return warnings, nil
Expand Down Expand Up @@ -287,7 +287,7 @@ func (cnf *Configurator) addOrUpdateIngress(ingEx *IngressEx) (Warnings, error)
name := objectMetaToFileName(&ingEx.Ingress.ObjectMeta)
content, err := cnf.templateExecutor.ExecuteIngressConfigTemplate(&nginxCfg)
if err != nil {
return warnings, fmt.Errorf("Error generating Ingress Config %v: %w", name, err)
return warnings, fmt.Errorf("error generating Ingress Config %v: %w", name, err)
}
cnf.nginxManager.CreateConfig(name, content)

Expand All @@ -302,11 +302,11 @@ func (cnf *Configurator) addOrUpdateIngress(ingEx *IngressEx) (Warnings, error)
func (cnf *Configurator) AddOrUpdateMergeableIngress(mergeableIngs *MergeableIngresses) (Warnings, error) {
warnings, err := cnf.addOrUpdateMergeableIngress(mergeableIngs)
if err != nil {
return warnings, fmt.Errorf("Error when adding or updating ingress %v/%v: %w", mergeableIngs.Master.Ingress.Namespace, mergeableIngs.Master.Ingress.Name, err)
return warnings, fmt.Errorf("error when adding or updating ingress %v/%v: %w", mergeableIngs.Master.Ingress.Namespace, mergeableIngs.Master.Ingress.Name, err)
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return warnings, fmt.Errorf("Error reloading NGINX for %v/%v: %w", mergeableIngs.Master.Ingress.Namespace, mergeableIngs.Master.Ingress.Name, err)
return warnings, fmt.Errorf("error reloading NGINX for %v/%v: %w", mergeableIngs.Master.Ingress.Namespace, mergeableIngs.Master.Ingress.Name, err)
}

return warnings, nil
Expand Down Expand Up @@ -341,7 +341,7 @@ func (cnf *Configurator) addOrUpdateMergeableIngress(mergeableIngs *MergeableIng
name := objectMetaToFileName(&mergeableIngs.Master.Ingress.ObjectMeta)
content, err := cnf.templateExecutor.ExecuteIngressConfigTemplate(&nginxCfg)
if err != nil {
return warnings, fmt.Errorf("Error generating Ingress Config %v: %w", name, err)
return warnings, fmt.Errorf("error generating Ingress Config %v: %w", name, err)
}
cnf.nginxManager.CreateConfig(name, content)

Expand Down Expand Up @@ -441,11 +441,11 @@ func (cnf *Configurator) deleteVirtualServerMetricsLabels(key string) {
func (cnf *Configurator) AddOrUpdateVirtualServer(virtualServerEx *VirtualServerEx) (Warnings, error) {
warnings, err := cnf.addOrUpdateVirtualServer(virtualServerEx)
if err != nil {
return warnings, fmt.Errorf("Error adding or updating VirtualServer %v/%v: %w", virtualServerEx.VirtualServer.Namespace, virtualServerEx.VirtualServer.Name, err)
return warnings, fmt.Errorf("error adding or updating VirtualServer %v/%v: %w", virtualServerEx.VirtualServer.Namespace, virtualServerEx.VirtualServer.Name, err)
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return warnings, fmt.Errorf("Error reloading NGINX for VirtualServer %v/%v: %w", virtualServerEx.VirtualServer.Namespace, virtualServerEx.VirtualServer.Name, err)
return warnings, fmt.Errorf("error reloading NGINX for VirtualServer %v/%v: %w", virtualServerEx.VirtualServer.Namespace, virtualServerEx.VirtualServer.Name, err)
}

return warnings, nil
Expand Down Expand Up @@ -473,7 +473,7 @@ func (cnf *Configurator) addOrUpdateVirtualServer(virtualServerEx *VirtualServer
vsCfg, warnings := vsc.GenerateVirtualServerConfig(virtualServerEx, apResources, dosResources)
content, err := cnf.templateExecutorV2.ExecuteVirtualServerTemplate(&vsCfg)
if err != nil {
return warnings, fmt.Errorf("Error generating VirtualServer config: %v: %w", name, err)
return warnings, fmt.Errorf("error generating VirtualServer config: %v: %w", name, err)
}
cnf.nginxManager.CreateConfig(name, content)

Expand All @@ -498,7 +498,7 @@ func (cnf *Configurator) AddOrUpdateVirtualServers(virtualServerExes []*VirtualS
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return allWarnings, fmt.Errorf("Error when reloading NGINX when updating Policy: %w", err)
return allWarnings, fmt.Errorf("error when reloading NGINX when updating Policy: %w", err)
}

return allWarnings, nil
Expand Down Expand Up @@ -630,7 +630,7 @@ func (cnf *Configurator) updateTLSPassthroughHostsConfig() error {

content, err := cnf.templateExecutorV2.ExecuteTLSPassthroughHostsTemplate(cfg)
if err != nil {
return fmt.Errorf("Error generating config for TLS Passthrough Unix Sockets map: %w", err)
return fmt.Errorf("error generating config for TLS Passthrough Unix Sockets map: %w", err)
}

cnf.nginxManager.CreateTLSPassthroughHostsConfig(content)
Expand Down Expand Up @@ -673,23 +673,23 @@ func (cnf *Configurator) AddOrUpdateResources(resources ExtendedResources) (Warn
for _, ingEx := range resources.IngressExes {
warnings, err := cnf.addOrUpdateIngress(ingEx)
if err != nil {
return nil, fmt.Errorf("Error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
return nil, fmt.Errorf("error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
}
allWarnings.Add(warnings)
}

for _, m := range resources.MergeableIngresses {
warnings, err := cnf.addOrUpdateMergeableIngress(m)
if err != nil {
return nil, fmt.Errorf("Error adding or updating mergeableIngress %v/%v: %w", m.Master.Ingress.Namespace, m.Master.Ingress.Name, err)
return nil, fmt.Errorf("error adding or updating mergeableIngress %v/%v: %w", m.Master.Ingress.Namespace, m.Master.Ingress.Name, err)
}
allWarnings.Add(warnings)
}

for _, vsEx := range resources.VirtualServerExes {
warnings, err := cnf.addOrUpdateVirtualServer(vsEx)
if err != nil {
return nil, fmt.Errorf("Error adding or updating VirtualServer %v/%v: %w", vsEx.VirtualServer.Namespace, vsEx.VirtualServer.Name, err)
return nil, fmt.Errorf("error adding or updating VirtualServer %v/%v: %w", vsEx.VirtualServer.Namespace, vsEx.VirtualServer.Name, err)
}
allWarnings.Add(warnings)
}
Expand All @@ -703,7 +703,7 @@ func (cnf *Configurator) AddOrUpdateResources(resources ExtendedResources) (Warn
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return nil, fmt.Errorf("Error when reloading NGINX when updating resources: %w", err)
return nil, fmt.Errorf("error when reloading NGINX when updating resources: %w", err)
}
return allWarnings, nil
}
Expand All @@ -723,7 +723,7 @@ func (cnf *Configurator) AddOrUpdateSpecialTLSSecrets(secret *api_v1.Secret, sec
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return fmt.Errorf("Error when reloading NGINX when updating the special Secrets: %w", err)
return fmt.Errorf("error when reloading NGINX when updating the special Secrets: %w", err)
}

return nil
Expand Down Expand Up @@ -762,7 +762,7 @@ func (cnf *Configurator) DeleteIngress(key string) error {
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return fmt.Errorf("Error when removing ingress %v: %w", key, err)
return fmt.Errorf("error when removing ingress %v: %w", key, err)
}

return nil
Expand All @@ -779,7 +779,7 @@ func (cnf *Configurator) DeleteVirtualServer(key string) error {
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return fmt.Errorf("Error when removing VirtualServer %v: %w", key, err)
return fmt.Errorf("error when removing VirtualServer %v: %w", key, err)
}

return nil
Expand All @@ -793,12 +793,12 @@ func (cnf *Configurator) DeleteTransportServer(key string) error {

err := cnf.deleteTransportServer(key)
if err != nil {
return fmt.Errorf("Error when removing TransportServer %v: %w", key, err)
return fmt.Errorf("error when removing TransportServer %v: %w", key, err)
}

err = cnf.reload(nginx.ReloadForOtherUpdate)
if err != nil {
return fmt.Errorf("Error when removing TransportServer %v: %w", key, err)
return fmt.Errorf("error when removing TransportServer %v: %w", key, err)
}

return nil
Expand Down Expand Up @@ -826,7 +826,7 @@ func (cnf *Configurator) UpdateEndpoints(ingExes []*IngressEx) error {
// It is safe to ignore warnings here as no new warnings should appear when updating Endpoints for Ingresses
_, err := cnf.addOrUpdateIngress(ingEx)
if err != nil {
return fmt.Errorf("Error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
return fmt.Errorf("error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
}

if cnf.isPlus {
Expand All @@ -844,7 +844,7 @@ func (cnf *Configurator) UpdateEndpoints(ingExes []*IngressEx) error {
}

if err := cnf.reload(nginx.ReloadForEndpointsUpdate); err != nil {
return fmt.Errorf("Error reloading NGINX when updating endpoints: %w", err)
return fmt.Errorf("error reloading NGINX when updating endpoints: %w", err)
}

return nil
Expand All @@ -858,7 +858,7 @@ func (cnf *Configurator) UpdateEndpointsMergeableIngress(mergeableIngresses []*M
// It is safe to ignore warnings here as no new warnings should appear when updating Endpoints for Ingresses
_, err := cnf.addOrUpdateMergeableIngress(mergeableIngresses[i])
if err != nil {
return fmt.Errorf("Error adding or updating mergeableIngress %v/%v: %w", mergeableIngresses[i].Master.Ingress.Namespace, mergeableIngresses[i].Master.Ingress.Name, err)
return fmt.Errorf("error adding or updating mergeableIngress %v/%v: %w", mergeableIngresses[i].Master.Ingress.Namespace, mergeableIngresses[i].Master.Ingress.Name, err)
}

if cnf.isPlus {
Expand All @@ -878,7 +878,7 @@ func (cnf *Configurator) UpdateEndpointsMergeableIngress(mergeableIngresses []*M
}

if err := cnf.reload(nginx.ReloadForEndpointsUpdate); err != nil {
return fmt.Errorf("Error reloading NGINX when updating endpoints for %v: %w", mergeableIngresses, err)
return fmt.Errorf("error reloading NGINX when updating endpoints for %v: %w", mergeableIngresses, err)
}

return nil
Expand All @@ -892,7 +892,7 @@ func (cnf *Configurator) UpdateEndpointsForVirtualServers(virtualServerExes []*V
// It is safe to ignore warnings here as no new warnings should appear when updating Endpoints for VirtualServers
_, err := cnf.addOrUpdateVirtualServer(vs)
if err != nil {
return fmt.Errorf("Error adding or updating VirtualServer %v/%v: %w", vs.VirtualServer.Namespace, vs.VirtualServer.Name, err)
return fmt.Errorf("error adding or updating VirtualServer %v/%v: %w", vs.VirtualServer.Namespace, vs.VirtualServer.Name, err)
}

if cnf.isPlus {
Expand All @@ -910,7 +910,7 @@ func (cnf *Configurator) UpdateEndpointsForVirtualServers(virtualServerExes []*V
}

if err := cnf.reload(nginx.ReloadForEndpointsUpdate); err != nil {
return fmt.Errorf("Error reloading NGINX when updating endpoints: %w", err)
return fmt.Errorf("error reloading NGINX when updating endpoints: %w", err)
}

return nil
Expand All @@ -925,7 +925,7 @@ func (cnf *Configurator) updatePlusEndpointsForVirtualServer(virtualServerEx *Vi

err := cnf.updateServersInPlus(upstream.Name, endpoints, serverCfg)
if err != nil {
return fmt.Errorf("Couldn't update the endpoints for %v: %w", upstream.Name, err)
return fmt.Errorf("couldn't update the endpoints for %v: %w", upstream.Name, err)
}
}

Expand Down Expand Up @@ -973,7 +973,7 @@ func (cnf *Configurator) updatePlusEndpointsForTransportServer(transportServerEx

err := cnf.updateStreamServersInPlus(name, endpoints)
if err != nil {
return fmt.Errorf("Couldn't update the endpoints for %v: %w", u.Name, err)
return fmt.Errorf("couldn't update the endpoints for %v: %w", u.Name, err)
}
}

Expand All @@ -999,7 +999,7 @@ func (cnf *Configurator) updatePlusEndpoints(ingEx *IngressEx) error {
name := getNameForUpstream(ingEx.Ingress, emptyHost, ingEx.Ingress.Spec.DefaultBackend)
err := cnf.updateServersInPlus(name, endps, cfg)
if err != nil {
return fmt.Errorf("Couldn't update the endpoints for %v: %w", name, err)
return fmt.Errorf("couldn't update the endpoints for %v: %w", name, err)
}
}
}
Expand All @@ -1021,7 +1021,7 @@ func (cnf *Configurator) updatePlusEndpoints(ingEx *IngressEx) error {
name := getNameForUpstream(ingEx.Ingress, rule.Host, &path.Backend)
err := cnf.updateServersInPlus(name, endps, cfg)
if err != nil {
return fmt.Errorf("Couldn't update the endpoints for %v: %w", name, err)
return fmt.Errorf("couldn't update the endpoints for %v: %w", name, err)
}
}
}
Expand Down Expand Up @@ -1156,19 +1156,19 @@ func (cnf *Configurator) UpdateTransportServers(updatedTSExes []*TransportServer
for _, tsEx := range updatedTSExes {
_, err := cnf.addOrUpdateTransportServer(tsEx)
if err != nil {
return fmt.Errorf("Error adding or updating TransportServer %v/%v: %w", tsEx.TransportServer.Namespace, tsEx.TransportServer.Name, err)
return fmt.Errorf("error adding or updating TransportServer %v/%v: %w", tsEx.TransportServer.Namespace, tsEx.TransportServer.Name, err)
}
}

for _, key := range deletedKeys {
err := cnf.deleteTransportServer(key)
if err != nil {
return fmt.Errorf("Error when removing TransportServer %v: %w", key, err)
return fmt.Errorf("error when removing TransportServer %v: %w", key, err)
}
}

if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return fmt.Errorf("Error when updating TransportServers: %w", err)
return fmt.Errorf("error when updating TransportServers: %w", err)
}

return nil
Expand Down Expand Up @@ -1379,12 +1379,12 @@ type ResourceOperation func(resource *v1beta1.DosProtectedResource, ingExes []*I
func (cnf *Configurator) AddOrUpdateAppProtectResource(resource *unstructured.Unstructured, ingExes []*IngressEx, mergeableIngresses []*MergeableIngresses, vsExes []*VirtualServerEx) (Warnings, error) {
warnings, err := cnf.addOrUpdateIngressesAndVirtualServers(ingExes, mergeableIngresses, vsExes)
if err != nil {
return warnings, fmt.Errorf("Error when updating %v %v/%v: %w", resource.GetKind(), resource.GetNamespace(), resource.GetName(), err)
return warnings, fmt.Errorf("error when updating %v %v/%v: %w", resource.GetKind(), resource.GetNamespace(), resource.GetName(), err)
}

err = cnf.reload(nginx.ReloadForOtherUpdate)
if err != nil {
return warnings, fmt.Errorf("Error when reloading NGINX when updating %v %v/%v: %w", resource.GetKind(), resource.GetNamespace(), resource.GetName(), err)
return warnings, fmt.Errorf("error when reloading NGINX when updating %v %v/%v: %w", resource.GetKind(), resource.GetNamespace(), resource.GetName(), err)
}

return warnings, nil
Expand All @@ -1411,23 +1411,23 @@ func (cnf *Configurator) addOrUpdateIngressesAndVirtualServers(ingExes []*Ingres
for _, ingEx := range ingExes {
warnings, err := cnf.addOrUpdateIngress(ingEx)
if err != nil {
return allWarnings, fmt.Errorf("Error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
return allWarnings, fmt.Errorf("error adding or updating ingress %v/%v: %w", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
}
allWarnings.Add(warnings)
}

for _, m := range mergeableIngresses {
warnings, err := cnf.addOrUpdateMergeableIngress(m)
if err != nil {
return allWarnings, fmt.Errorf("Error adding or updating mergeableIngress %v/%v: %w", m.Master.Ingress.Namespace, m.Master.Ingress.Name, err)
return allWarnings, fmt.Errorf("error adding or updating mergeableIngress %v/%v: %w", m.Master.Ingress.Namespace, m.Master.Ingress.Name, err)
}
allWarnings.Add(warnings)
}

for _, vs := range vsExes {
warnings, err := cnf.addOrUpdateVirtualServer(vs)
if err != nil {
return allWarnings, fmt.Errorf("Error adding or updating VirtualServer %v/%v: %w", vs.VirtualServer.Namespace, vs.VirtualServer.Name, err)
return allWarnings, fmt.Errorf("error adding or updating VirtualServer %v/%v: %w", vs.VirtualServer.Namespace, vs.VirtualServer.Name, err)
}
allWarnings.Add(warnings)
}
Expand Down Expand Up @@ -1503,11 +1503,11 @@ func (cnf *Configurator) AddInternalRouteConfig() error {
mainCfg := GenerateNginxMainConfig(cnf.staticCfgParams, cnf.cfgParams)
mainCfgContent, err := cnf.templateExecutor.ExecuteMainConfigTemplate(mainCfg)
if err != nil {
return fmt.Errorf("Error when writing main Config: %w", err)
return fmt.Errorf("error when writing main Config: %w", err)
}
cnf.nginxManager.CreateMainConfig(mainCfgContent)
if err := cnf.reload(nginx.ReloadForOtherUpdate); err != nil {
return fmt.Errorf("Error when reloading nginx: %w", err)
return fmt.Errorf("error when reloading nginx: %w", err)
}
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions internal/configs/parsing_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func ParseLBMethod(method string) (string, error) {
return method, nil
}

return "", fmt.Errorf("Invalid load balancing method: %q", method)
return "", fmt.Errorf("invalid load balancing method: %q", method)
}

var nginxLBValidInput = map[string]bool{
Expand Down Expand Up @@ -147,7 +147,7 @@ func ParseLBMethodForPlus(method string) (string, error) {
return method, nil
}

return "", fmt.Errorf("Invalid load balancing method: %q", method)
return "", fmt.Errorf("invalid load balancing method: %q", method)
}

func validateHashLBMethod(method string) (string, error) {
Expand Down Expand Up @@ -222,7 +222,7 @@ func ParseOffset(s string) (string, error) {
if offsetRegexp.MatchString(s) {
return s, nil
}
return "", errors.New("Invalid offset string")
return "", errors.New("invalid offset string")
}

// SizeFmt http://nginx.org/en/docs/syntax.html
Expand All @@ -237,7 +237,7 @@ func ParseSize(s string) (string, error) {
if sizeRegexp.MatchString(s) {
return s, nil
}
return "", errors.New("Invalid size string")
return "", errors.New("invalid size string")
}

// https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers
Expand All @@ -250,7 +250,7 @@ func ParseProxyBuffersSpec(s string) (string, error) {
if proxyBuffersRegexp.MatchString(s) {
return s, nil
}
return "", errors.New("Invalid proxy buffers string")
return "", errors.New("invalid proxy buffers string")
}

// ParsePortList ensures that the string is a comma-separated list of port numbers
Expand All @@ -269,11 +269,11 @@ func ParsePortList(s string) ([]int, error) {
func parsePort(value string) (int, error) {
port, err := strconv.ParseInt(value, 10, 16)
if err != nil {
return 0, fmt.Errorf("Unable to parse port as integer: %w", err)
return 0, fmt.Errorf("unable to parse port as integer: %w", err)
}

if port <= 0 {
return 0, fmt.Errorf("Port number should be greater than zero: %q", port)
return 0, fmt.Errorf("port number should be greater than zero: %q", port)
}

return int(port), nil
Expand Down
Loading