Skip to content

Commit

Permalink
Merge pull request #291 from zlabjp/update-doc
Browse files Browse the repository at this point in the history
Update doc
  • Loading branch information
tatsuhiro-t authored Jan 29, 2024
2 parents 634af2e + 3a8e996 commit 222df46
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func unmarshal(ctx context.Context, data []byte, dest interface{}) error {
log.Error(err, "Unable to unmarshal YAML string; fall back to JSON")

if err := json.Unmarshal(data, dest); err != nil {
return fmt.Errorf("could not unmarshal JSON string: %w", err)
return fmt.Errorf("unable to unmarshal JSON string: %w", err)
}

return nil
Expand Down
20 changes: 10 additions & 10 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ func (lbc *LoadBalancerController) createUpstream(ctx context.Context, ing *netw
func (lbc *LoadBalancerController) getTLSCredFromSecret(ctx context.Context, key *types.NamespacedName) (*nghttpx.TLSCred, error) {
secret, err := lbc.secretLister.Secrets(key.Namespace).Get(key.Name)
if err != nil {
return nil, fmt.Errorf("could not get TLS secret %v: %w", key, err)
return nil, fmt.Errorf("unable to get TLS secret %v: %w", key, err)
}
tlsCred, err := lbc.createTLSCredFromSecret(ctx, secret)
if err != nil {
Expand All @@ -1629,7 +1629,7 @@ func (lbc *LoadBalancerController) getTLSCredFromIngress(ctx context.Context, in
tls := &ing.Spec.TLS[i]
secret, err := lbc.secretLister.Secrets(ing.Namespace).Get(tls.SecretName)
if err != nil {
return nil, fmt.Errorf("could not retrieve Secret %v/%v for Ingress %v/%v: %w", ing.Namespace, tls.SecretName, ing.Namespace, ing.Name, err)
return nil, fmt.Errorf("unable to retrieve Secret %v/%v for Ingress %v/%v: %w", ing.Namespace, tls.SecretName, ing.Namespace, ing.Name, err)
}
tlsCred, err := lbc.createTLSCredFromSecret(ctx, secret)
if err != nil {
Expand Down Expand Up @@ -1668,12 +1668,12 @@ func (lbc *LoadBalancerController) createTLSCredFromSecret(ctx context.Context,

cert, err = nghttpx.NormalizePEM(cert)
if err != nil {
return nil, fmt.Errorf("could not normalize certificate in Secret %v/%v: %w", secret.Namespace, secret.Name, err)
return nil, fmt.Errorf("unable to normalize certificate in Secret %v/%v: %w", secret.Namespace, secret.Name, err)
}

key, err = nghttpx.NormalizePEM(key)
if err != nil {
return nil, fmt.Errorf("could not normalize private key in Secret %v/%v: %w", secret.Namespace, secret.Name, err)
return nil, fmt.Errorf("unable to normalize private key in Secret %v/%v: %w", secret.Namespace, secret.Name, err)
}

if _, err := tls.X509KeyPair(cert, key); err != nil {
Expand Down Expand Up @@ -2090,7 +2090,7 @@ func (lbc *LoadBalancerController) resolveTargetPort(svcPort *corev1.ServicePort
case svcPort.TargetPort.StrVal != "":
port, err := lbc.getNamedPortFromPod(ref, svcPort)
if err != nil {
return 0, fmt.Errorf("could not find named port %v in Pod spec: %w", svcPort.TargetPort.String(), err)
return 0, fmt.Errorf("unable to find named port %v in Pod spec: %w", svcPort.TargetPort.String(), err)
}
if *epPort.Port == port {
return *epPort.Port, nil
Expand All @@ -2109,12 +2109,12 @@ func (lbc *LoadBalancerController) resolveTargetPort(svcPort *corev1.ServicePort
func (lbc *LoadBalancerController) getNamedPortFromPod(ref *corev1.ObjectReference, servicePort *corev1.ServicePort) (int32, error) {
pod, err := lbc.podLister.Pods(ref.Namespace).Get(ref.Name)
if err != nil {
return 0, fmt.Errorf("could not get Pod %v/%v: %w", ref.Namespace, ref.Name, err)
return 0, fmt.Errorf("unable to get Pod %v/%v: %w", ref.Namespace, ref.Name, err)
}

port, err := podFindPort(pod, servicePort)
if err != nil {
return 0, fmt.Errorf("could not find port %v from Pod %v/%v: %w", servicePort.TargetPort.String(), pod.Namespace, pod.Name, err)
return 0, fmt.Errorf("unable to find port %v from Pod %v/%v: %w", servicePort.TargetPort.String(), pod.Namespace, pod.Name, err)
}
return port, nil
}
Expand Down Expand Up @@ -3000,7 +3000,7 @@ func (lc *LeaderController) getLoadBalancerIngress(ctx context.Context) ([]netwo
var err error
lbIngs, err = lc.getLoadBalancerIngressSelector(ctx, podLabelSelector(lc.lbc.pod.Labels))
if err != nil {
return nil, fmt.Errorf("could not get Pod or Node IP of Ingress controller: %w", err)
return nil, fmt.Errorf("unable to get Pod or Node IP of Ingress controller: %w", err)
}
} else {
svc, err := lc.svcLister.Services(lc.lbc.publishService.Namespace).Get(lc.lbc.publishService.Name)
Expand All @@ -3023,7 +3023,7 @@ func (lc *LeaderController) getLoadBalancerIngressSelector(ctx context.Context,

pods, err := lc.podLister.List(selector)
if err != nil {
return nil, fmt.Errorf("could not list Pods with label %v", selector)
return nil, fmt.Errorf("unable to list Pods with label %v", selector)
}

if len(pods) == 0 {
Expand Down Expand Up @@ -3067,7 +3067,7 @@ func (lc *LeaderController) getLoadBalancerIngressSelector(ctx context.Context,
func (lc *LeaderController) getPodNodeAddress(pod *corev1.Pod) (string, error) {
node, err := lc.nodeLister.Get(pod.Spec.NodeName)
if err != nil {
return "", fmt.Errorf("could not get Node %v for Pod %v/%v from lister: %w", pod.Spec.NodeName, pod.Namespace, pod.Name, err)
return "", fmt.Errorf("unable to get Node %v for Pod %v/%v from lister: %w", pod.Spec.NodeName, pod.Namespace, pod.Name, err)
}
var externalIP string
for i := range node.Status.Addresses {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (f *fixture) run() {
f.setupStore()

if err := f.lbc.sync(context.Background(), syncKey); err != nil {
f.t.Errorf("Failed to sync: %v", err)
f.t.Errorf("Unable to sync: %v", err)
}

f.verifyActions()
Expand Down Expand Up @@ -1787,7 +1787,7 @@ func TestSyncIngress(t *testing.T) {
updatedIng, err := f.clientset.NetworkingV1().Ingresses(tt.ingress.Namespace).
Get(context.Background(), tt.ingress.Name, metav1.GetOptions{})
if err != nil {
t.Fatalf("Could not get Ingress %v/%v: %v", tt.ingress.Namespace, tt.ingress.Name, err)
t.Fatalf("Unable to get Ingress %v/%v: %v", tt.ingress.Namespace, tt.ingress.Name, err)
}

if got, want := updatedIng.Status.LoadBalancer.Ingress, tt.wantLoadBalancerIngresses; !reflect.DeepEqual(got, want) {
Expand Down Expand Up @@ -2089,7 +2089,7 @@ func TestSyncQUICKeyingMaterials(t *testing.T) {

updatedSecret, err := f.clientset.CoreV1().Secrets(defaultQUICSecret.Namespace).Get(context.Background(), defaultQUICSecret.Name, metav1.GetOptions{})
if err != nil {
t.Fatalf("Could not get Secret %v/%v: %v", defaultQUICSecret.Namespace, defaultQUICSecret.Name, err)
t.Fatalf("Unable to get Secret %v/%v: %v", defaultQUICSecret.Namespace, defaultQUICSecret.Name, err)
}

if tt.wantKeepTimestamp {
Expand Down
26 changes: 13 additions & 13 deletions pkg/nghttpx/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (lb *LoadBalancer) CheckAndReload(ctx context.Context, ingressCfg *IngressC

changed, err := lb.checkAndWriteCfg(ctx, ingressCfg, mainConfig, backendConfig)
if err != nil {
return false, fmt.Errorf("failed to write new nghttpx configuration. Avoiding reload: %w", err)
return false, fmt.Errorf("unable to write new nghttpx configuration. Avoiding reload: %w", err)
}

if changed == configNotChanged {
Expand Down Expand Up @@ -126,7 +126,7 @@ func (lb *LoadBalancer) CheckAndReload(ctx context.Context, ingressCfg *IngressC

log.Info("Change in configuration detected. Reloading...")
if err := lb.cmd.Process.Signal(syscall.SIGHUP); err != nil {
return false, fmt.Errorf("failed to send signal to nghttpx process (PID %v): %w", lb.cmd.Process.Pid, err)
return false, fmt.Errorf("unable to to send signal to nghttpx process (PID %v): %w", lb.cmd.Process.Pid, err)
}

if err := lb.waitUntilConfigRevisionChanges(ctx, oldConfRev); err != nil {
Expand All @@ -146,7 +146,7 @@ func (lb *LoadBalancer) CheckAndReload(ctx context.Context, ingressCfg *IngressC
}

if err := lb.issueBackendReplaceRequest(ctx, ingressCfg); err != nil {
return false, fmt.Errorf("failed to issue backend replace request: %w", err)
return false, fmt.Errorf("unable to issue backend replace request: %w", err)
}

lb.eventRecorder.Eventf(lb.pod, nil, corev1.EventTypeNormal, "ReplaceBackend", "ReplaceBackend", "nghttpx replaced its backend servers")
Expand All @@ -162,10 +162,10 @@ func (lb *LoadBalancer) CheckAndReload(ctx context.Context, ingressCfg *IngressC
// deleteStaleAssets deletes asset files which are no longer used.
func (lb *LoadBalancer) deleteStaleAssets(ctx context.Context, ingConfig *IngressConfig, t time.Time) error {
if err := lb.deleteStaleTLSAssets(ctx, ingConfig, t); err != nil {
return fmt.Errorf("could not delete stale TLS assets: %w", err)
return fmt.Errorf("unable to delete stale TLS assets: %w", err)
}
if err := lb.deleteStaleMrubyAssets(ctx, ingConfig, t); err != nil {
return fmt.Errorf("could not delete stale mruby assets: %w", err)
return fmt.Errorf("unable to delete stale mruby assets: %w", err)
}
return nil
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func (lb *LoadBalancer) issueBackendReplaceRequest(ctx context.Context, ingConfi

in, err := os.Open(backendConfigPath)
if err != nil {
return fmt.Errorf("could not open backend configuration file %v: %w", backendConfigPath, err)
return fmt.Errorf("unable to open backend configuration file %v: %w", backendConfigPath, err)
}

defer in.Close()
Expand All @@ -233,15 +233,15 @@ func (lb *LoadBalancer) issueBackendReplaceRequest(ctx context.Context, ingConfi

req, err := http.NewRequestWithContext(ctx, http.MethodPost, lb.backendconfigURI, in)
if err != nil {
return fmt.Errorf("could not create API request: %w", err)
return fmt.Errorf("unable to create API request: %w", err)
}

req.Header.Add("Content-Type", "text/plain")

resp, err := lb.httpClient.Do(req)

if err != nil {
return fmt.Errorf("could not issue API request: %w", err)
return fmt.Errorf("unable to issue API request: %w", err)
}

defer resp.Body.Close()
Expand All @@ -252,7 +252,7 @@ func (lb *LoadBalancer) issueBackendReplaceRequest(ctx context.Context, ingConfi

respBody, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("could not read API response body: %w", err)
return fmt.Errorf("unable to read API response body: %w", err)
}

if log.V(3).Enabled() {
Expand Down Expand Up @@ -282,12 +282,12 @@ func (lb *LoadBalancer) getNghttpxConfigRevision(ctx context.Context) (int64, er

req, err := http.NewRequestWithContext(ctx, http.MethodGet, lb.configrevisionURI, nil)
if err != nil {
return 0, fmt.Errorf("could not create API request: %w", err)
return 0, fmt.Errorf("unable to create API request: %w", err)
}

resp, err := lb.httpClient.Do(req)
if err != nil {
return 0, fmt.Errorf("could not get nghttpx configRevision: %w", err)
return 0, fmt.Errorf("unable to get nghttpx configRevision: %w", err)
}

defer resp.Body.Close()
Expand All @@ -300,7 +300,7 @@ func (lb *LoadBalancer) getNghttpxConfigRevision(ctx context.Context) (int64, er

var r apiResult
if err := d.Decode(&r); err != nil {
return 0, fmt.Errorf("could not parse nghttpx configuration API result: %w", err)
return 0, fmt.Errorf("unable to parse nghttpx configuration API result: %w", err)
}

if r.Data == nil {
Expand Down Expand Up @@ -337,7 +337,7 @@ func (lb *LoadBalancer) waitUntilConfigRevisionChanges(ctx context.Context, oldC

return true, nil
}); err != nil {
return fmt.Errorf("could not get new nghttpx configRevision: %w", err)
return fmt.Errorf("unable to get new nghttpx configRevision: %w", err)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/nghttpx/mruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func writeMrubyFile(ingConfig *IngressConfig) error {

f := ingConfig.MrubyFile
if err := WriteFile(f.Path, f.Content); err != nil {
return fmt.Errorf("failed to write mruby file: %w", err)
return fmt.Errorf("unable to write mruby file: %w", err)
}

return nil
Expand All @@ -45,13 +45,13 @@ func writePerPatternMrubyFile(ingConfig *IngressConfig) error {
continue
}
if err := WriteFile(upstream.Mruby.Path, upstream.Mruby.Content); err != nil {
return fmt.Errorf("failed to write per-pattern mruby file: %w", err)
return fmt.Errorf("unable to write per-pattern mruby file: %w", err)
}
}

if f := ingConfig.HealthzMruby; f != nil {
if err := WriteFile(f.Path, f.Content); err != nil {
return fmt.Errorf("failed to write healthz mruby file: %w", err)
return fmt.Errorf("unable to write healthz mruby file: %w", err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/nghttpx/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func writeQUICSecretFile(ingConfig *IngressConfig) error {

f := ingConfig.QUICSecretFile
if err := WriteFile(f.Path, f.Content); err != nil {
return fmt.Errorf("failed to write QUIC secret file: %w", err)
return fmt.Errorf("unable to write QUIC secret file: %w", err)
}

return nil
Expand All @@ -56,12 +56,12 @@ func VerifyQUICKeyingMaterials(km []byte) error {
}

if _, err := hex.DecodeString(l); err != nil {
return fmt.Errorf("could not decode QUIC keying materials from hex string: %w", err)
return fmt.Errorf("unable to decode QUIC keying materials from hex string: %w", err)
}
}

if err := sc.Err(); err != nil {
return fmt.Errorf("could not read QUIC keying materials: %w", err)
return fmt.Errorf("unable to read QUIC keying materials: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/nghttpx/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ func (lb *LoadBalancer) writeDefaultNghttpxConfig(nghttpxConfDir string, nghttpx
"HealthPort": nghttpxHealthPort,
"APIPort": nghttpxAPIPort,
}); err != nil {
return fmt.Errorf("could not create default configuration file for nghttpx: %w", err)
return fmt.Errorf("unable to not create default configuration file for nghttpx: %w", err)
}

if err := WriteFile(ConfigPath(nghttpxConfDir), buf.Bytes()); err != nil {
return fmt.Errorf("could not write default configuration file for nghttpx: %w", err)
return fmt.Errorf("unable to write default configuration file for nghttpx: %w", err)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/nghttpx/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func CreateTLSCred(dir, name string, cert, key, ocspResp []byte) *TLSCred {
// writeTLSKeyCert writes TLS private keys and certificates to their files.
func writeTLSKeyCert(ingConfig *IngressConfig) error {
if err := MkdirAll(filepath.Join(ingConfig.ConfDir, tlsDir)); err != nil {
return fmt.Errorf("failed to create TLS directory: %w", err)
return fmt.Errorf("unable to create TLS directory: %w", err)
}

if ingConfig.DefaultTLSCred != nil {
Expand All @@ -115,16 +115,16 @@ func writeTLSKeyCert(ingConfig *IngressConfig) error {
// writeTLSCred writes TLS private key, certificate, and optionally OCSP response to tlsCred in their files.
func writeTLSCred(tlsCred *TLSCred) error {
if err := WriteFile(tlsCred.Key.Path, tlsCred.Key.Content); err != nil {
return fmt.Errorf("failed to write TLS private key: %w", err)
return fmt.Errorf("unable to write TLS private key: %w", err)
}

if err := WriteFile(tlsCred.Cert.Path, tlsCred.Cert.Content); err != nil {
return fmt.Errorf("failed to write TLS certificate: %w", err)
return fmt.Errorf("unable to write TLS certificate: %w", err)
}

if tlsCred.OCSPResp != nil {
if err := WriteFile(tlsCred.OCSPResp.Path, tlsCred.OCSPResp.Content); err != nil {
return fmt.Errorf("failed to write TLS OCSP response: %w", err)
return fmt.Errorf("unable to write TLS OCSP response: %w", err)
}
}

Expand Down

0 comments on commit 222df46

Please sign in to comment.