Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions internal/mode/static/nginx/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ func (n *NginxUpdaterImpl) UpdateConfig(
deployment *Deployment,
files []File,
) bool {
n.logger.Info("Sending nginx configuration to agent")

msg := deployment.SetFiles(files)
applied := deployment.GetBroadcaster().Send(msg)
if applied {
n.logger.Info("Sent nginx configuration to agent")
}

deployment.SetLatestConfigError(deployment.GetConfigurationStatus())

Expand Down
22 changes: 17 additions & 5 deletions internal/mode/static/nginx/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
// If any connection or unrecoverable errors occur, return and agent should re-establish a subscription.
// If errors occur with applying the config, log and put those errors into the status queue to be written
// to the Gateway status.
func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error {

Check failure on line 122 in internal/mode/static/nginx/agent/command.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

cyclomatic complexity 18 of func `(*commandService).Subscribe` is high (> 15) (gocyclo)
ctx := in.Context()

gi, ok := grpcContext.GrpcInfoFromContext(ctx)
Expand Down Expand Up @@ -179,6 +179,7 @@
panic(fmt.Sprintf("unknown request type %d", msg.Type))
}

cs.logger.V(1).Info("Sending configuration to agent", "requestType", msg.Type)
if err := msgr.Send(ctx, req); err != nil {
cs.logger.Error(err, "error sending request to agent")
deployment.SetPodErrorStatus(conn.PodName, err)
Expand All @@ -189,7 +190,10 @@
case err = <-msgr.Errors():
cs.logger.Error(err, "connection error", "pod", conn.PodName)
deployment.SetPodErrorStatus(conn.PodName, err)
channels.ResponseCh <- struct{}{}
select {
case channels.ResponseCh <- struct{}{}:
default:
}

if errors.Is(err, io.EOF) {
return grpcStatus.Error(codes.Aborted, err.Error())
Expand All @@ -198,7 +202,12 @@
case msg := <-msgr.Messages():
res := msg.GetCommandResponse()
if res.GetStatus() != pb.CommandResponse_COMMAND_STATUS_OK {
err := fmt.Errorf("bad response from agent: msg: %s; error: %s", res.GetMessage(), res.GetError())
if strings.Contains(res.GetMessage(), "rollback successful") ||
strings.Contains(strings.ToLower(res.GetMessage()), "rollback failed") {
// we don't care about these messages, so ignore them
continue
}
err := fmt.Errorf("msg: %s; error: %s", res.GetMessage(), res.GetError())
deployment.SetPodErrorStatus(conn.PodName, err)
} else {
deployment.SetPodErrorStatus(conn.PodName, nil)
Expand Down Expand Up @@ -268,6 +277,8 @@
for _, action := range deployment.GetNGINXPlusActions() {
// retry the API update request because sometimes nginx isn't quite ready after the config apply reload
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
var overallUpstreamApplyErr error

if err := wait.PollUntilContextCancel(
timeoutCtx,
500*time.Millisecond,
Expand All @@ -287,13 +298,14 @@
}

if upstreamApplyErr != nil {
overallUpstreamApplyErr = errors.Join(overallUpstreamApplyErr, upstreamApplyErr)
return false, nil //nolint:nilerr // this error is collected at the end

Check failure on line 302 in internal/mode/static/nginx/agent/command.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

directive `//nolint:nilerr // this error is collected at the end` is unused for linter "nilerr" (nolintlint)
}
return true, nil
},
); err != nil {
if strings.Contains(err.Error(), "bad response from agent") {
errs = append(errs, err)
if overallUpstreamApplyErr != nil {
errs = append(errs, overallUpstreamApplyErr)
} else {
cancel()
return err
Expand Down Expand Up @@ -330,7 +342,7 @@
case msg := <-msgr.Messages():
res := msg.GetCommandResponse()
if res.GetStatus() != pb.CommandResponse_COMMAND_STATUS_OK {
applyErr := fmt.Errorf("bad response from agent: msg: %s; error: %s", res.GetMessage(), res.GetError())
applyErr := fmt.Errorf("msg: %s; error: %s", res.GetMessage(), res.GetError())
return applyErr, nil
}

Expand Down
2 changes: 2 additions & 0 deletions internal/mode/static/nginx/agent/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (fs *fileService) GetFile(
return nil, status.Errorf(codes.NotFound, "file not found")
}

fs.logger.V(1).Info("Getting file for agent", "file", filename)

return &pb.GetFileResponse{
Contents: &pb.FileContents{
Contents: contents,
Expand Down
2 changes: 2 additions & 0 deletions internal/mode/static/nginx/config/plus_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
var plusAPITemplate = gotemplate.Must(gotemplate.New("plusAPI").Parse(plusAPITemplateText))

func executePlusAPI(conf dataplane.Configuration) []executeResult {
result := executeResult{

Check failure on line 13 in internal/mode/static/nginx/config/plus_api.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

ineffectual assignment to result (ineffassign)
dest: nginxPlusConfigFile,
}
// if AllowedAddresses is empty, it means that we are not running on nginx plus, and we don't want this generated
Expand All @@ -19,6 +19,8 @@
dest: nginxPlusConfigFile,
data: helpers.MustExecuteTemplate(plusAPITemplate, conf.NginxPlus),
}
} else {
return nil
}

return []executeResult{result}
Expand Down
18 changes: 2 additions & 16 deletions internal/mode/static/nginx/config/plus_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,7 @@ func TestExecutePlusAPI_EmptyNginxPlus(t *testing.T) {
}

g := NewWithT(t)
expSubStrings := map[string]int{
"listen unix:/var/run/nginx/nginx-plus-api.sock;": 0,
"access_log off;": 0,
"api write=on;": 0,
"listen 8765;": 0,
"root /usr/share/nginx/html;": 0,
"allow 127.0.0.1;": 0,
"deny all;": 0,
"location = /dashboard.html {}": 0,
"api write=off;": 0,
}

for expSubStr, expCount := range expSubStrings {
res := executePlusAPI(conf)
g.Expect(res).To(HaveLen(1))
g.Expect(expCount).To(Equal(strings.Count(string(res[0].data), expSubStr)))
}
res := executePlusAPI(conf)
g.Expect(res).To(BeNil())
}
Loading