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

feat: Logic to apply AuthProxyWorkload spec to workload containers #26

Merged
merged 8 commits into from
Sep 28, 2022

Conversation

hessjcg
Copy link
Collaborator

@hessjcg hessjcg commented Sep 21, 2022

Updates the containers on a workload to properly implement the AuthProxyWorkload specs that apply to that workload.

Updates the containers on a workload to properly implement the
AuthProxyWorkload specs that apply to that workload.
@hessjcg hessjcg requested a review from a team September 21, 2022 19:59
@hessjcg hessjcg marked this pull request as draft September 21, 2022 20:33
@hessjcg hessjcg marked this pull request as ready for review September 23, 2022 16:20
)

func TestMain(m *testing.M) {
// Log is the test logger used by the integration tests and server.
Copy link
Member

Choose a reason for hiding this comment

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

s/Log/logger/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

internal/podspec_updates_test.go Outdated Show resolved Hide resolved
internal/podspec_updates_test.go Show resolved Hide resolved
},
Instances: instances,
},
Status: cloudsqlapi.AuthProxyWorkloadStatus{},
Copy link
Member

Choose a reason for hiding this comment

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

here's another case where you don't need to do this and can just rely on the zero value

Copy link
Member

Choose a reason for hiding this comment

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

Ditto below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

}
}

func proxies(wl *internal.DeploymentWorkload, proxies ...*cloudsqlapi.AuthProxyWorkload) []*cloudsqlapi.AuthProxyWorkload {
Copy link
Member

Choose a reason for hiding this comment

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

A comment above this function would help me. I see what the code is doing, but I'd still appreciate some context. Maybe a better function name would help? markProxiesForUpdate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. I renamed this function and added a comment to explain why this is needed.

internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved

func (state *updateState) addHealthCheck(csqlWorkload *cloudsqlapi.AuthProxyWorkload) int32 {
var port int32
if csqlWorkload.Spec.AuthProxyContainer != nil &&
Copy link
Member

Choose a reason for hiding this comment

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

port := DefaultHealthCheckPort

healthCheckEnabled := func() bool {
  return csqlWorkload.Spec.AuthProxyContainer != nil &&
		csqlWorkload.Spec.AuthProxyContainer.Telemetry != nil &&
		csqlWorkload.Spec.AuthProxyContainer.Telemetry.HTTPPort != nil
}
if !heathCheckEnabled() {
  for state.isPortInUse(port) {
    port++
  }
  return port
}

port = *csqlWorkload.Spec.AuthProxyContainer.Telemetry.HTTPPort
if state.isPortInUse(port) {
  state.addError(ErrorCodePortConflict,
    fmt.Sprintf("telemetry httpPort %d is already in use", port), csqlWorkload)
}

return port

I prefer early returns here. But else would be fine as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The healthcheck is always enabled. However, the customer may override the default port when they want to use their own port so that they can use Prometheus too.

Copy link
Member

Choose a reason for hiding this comment

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

My point is this code is hard to read. You could move the various boolean checks behind a function that describes what the checks are doing.

Also, you have an empty else block below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This if statement doesn't indicate an error or exception state. There are really two possibilities, and there is no judgement about which is "default" or "error". I rewrote it to make the code more terse, and added a few comments for clarity. I can't figure out a way to make this simpler. I think factoring this check into a separate function is more complex.

}

func (state *updateState) applyAuthenticationSpec(proxy *cloudsqlapi.AuthProxyWorkload, container *corev1.Container, args []string) []string {
if proxy.Spec.Authentication == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is there some code missing here? Should it wait until the next PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is missing code, but it should wait for another PR. We need E2e tests in place before we can check if authentication is implemented correctly.

@enocom enocom requested a review from kurtisvg September 26, 2022 16:20
@hessjcg hessjcg requested a review from enocom September 27, 2022 16:11
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved

func (state *updateState) addHealthCheck(csqlWorkload *cloudsqlapi.AuthProxyWorkload) int32 {
var port int32
if csqlWorkload.Spec.AuthProxyContainer != nil &&
Copy link
Member

Choose a reason for hiding this comment

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

My point is this code is hard to read. You could move the various boolean checks behind a function that describes what the checks are doing.

Also, you have an empty else block below.

Instances: instances,
})
}
func basicProxy(name string, spec cloudsqlapi.AuthProxyWorkloadSpec) *cloudsqlapi.AuthProxyWorkload {
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between basicProxy and simpleAuthProxy? What are better names for these functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed authProxyWorkloadFromSpec.

internal/podspec_updates_test.go Outdated Show resolved Hide resolved
internal/podspec_updates_test.go Outdated Show resolved Hide resolved
internal/podspec_updates_test.go Outdated Show resolved Hide resolved
internal/podspec_updates_test.go Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@hessjcg hessjcg left a comment

Choose a reason for hiding this comment

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

More revisions and comments.

@hessjcg hessjcg requested a review from enocom September 28, 2022 15:00
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates.go Outdated Show resolved Hide resolved
internal/podspec_updates_test.go Show resolved Hide resolved
internal/podspec_updates_test.go Outdated Show resolved Hide resolved
@hessjcg hessjcg merged commit 17b73c0 into main Sep 28, 2022
@hessjcg hessjcg deleted the internal-update-workload branch September 28, 2022 17:22
This was referenced Dec 7, 2022
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.

3 participants