Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading api-address from config file in container #874

Merged
merged 9 commits into from
Aug 5, 2024

Conversation

mmatczuk
Copy link
Contributor

This patchset implements checking readiness over a Unix socket.
Unnecessary API servers in e2e tests are removed.
The ready command implementation is extended and improved for better reuse.

Fixes #873

@mmatczuk mmatczuk requested a review from Choraden as a code owner July 31, 2024 13:47
@@ -2,6 +2,8 @@ ARG BASE_IMAGE=gcr.io/distroless/static:nonroot

FROM ${BASE_IMAGE}

ENV PLATFORM=container
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about FORWARDER_PLATFORM? Something to make it difficult to overwrite.

Copy link
Contributor Author

@mmatczuk mmatczuk Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, the FORWARDER_PLATFORM does not make much sense to me.

We have two situations:

  • The PLATFORM env var gets overwritten by hand when running container - for that we could log warning in the readiness check.
  • Our container behavior kicking in in another setting due to presence of the env var - here I think we are good since we must match both key and value (container)

Let me add some more logging instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered adding sth like this

	if p := os.Getenv("PLATFORM"); p != "" {
		if  p == "container" {
			c.apiAddr = "unix:" + cfg.APIUnixSocket
		} else {
			fmt.Fprintf(os.Stderr, "unexpected PLATFORM environment variable: %q\n", p)
		}
	}

But I guess it's not really useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugly^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm exaggerating, why would somebody add PLATFORM variable to forwarder container.

s.Close()
}()

return s.Serve(l)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns an error on server close

^C2024/08/01 08:12:27.518332 [ERROR] fatal error exiting: http: Server closed
exit status 1

"time"
)

func ServeUnixSocket(ctx context.Context, h http.Handler, socketPath string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May we add some logging here?

Copy link
Contributor Author

@mmatczuk mmatczuk Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any logging should go in handler as this is a helper function.

Copy link
Contributor

@Choraden Choraden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmatczuk mmatczuk merged commit 926558a into main Aug 5, 2024
6 checks passed
@mmatczuk mmatczuk deleted the mmt/fix_docker_api_address branch August 5, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker: use unix socket for health checks
2 participants