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

Watch for Secrets (draft) #765

Closed
wants to merge 1 commit into from

Conversation

pleshakov
Copy link
Contributor

Proposed changes

Problem:
Watch for secret updates
Solves #553

Solution:
Watch for secret updates

NOTE: this PR is a prototype. Need your comments about the design. (Please ignore low level details).

Key design decisions:

  • Stop processing Secrets separately and make them part of the Graph.
  • Use the Graph as a source for determining relationship between a Secret and NKG configuration.
  • Handle Secrets in dataplane.Configuration and in the Generator rather than separately. I don't see any need to handle them separately, but handling them along other resource types makes things simpler.
  • Change file.Manager so that it can accept a list of files. Also, extend it so that deletes all the files from the previous configuration version, so that we don't have any orphan Secrets on the file system.

We can further refactor the code to get rid of relationship.Capturer completely in favour of using the Graph as a single source of truth about relationships among the resources.

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Problem:
Watch for secret updates
Solves nginxinc#553

Solution:
Watch for secret updates
@pleshakov pleshakov requested a review from a team as a code owner June 16, 2023 20:42
@github-actions github-actions bot added the enhancement New feature or request label Jun 16, 2023
Copy link
Contributor

@sjberman sjberman left a comment

Choose a reason for hiding this comment

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

Overall I think this approach looks good.

return generated
files = append(files, file.File{
Content: generated,
Path: "/etc/nginx/conf.d/http.conf",
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's either make this a const, or what if we updated our dataplane.Configuration to have an http section, and in the future we'd add a stream section, where each could contain their respective configs and file paths? That's probably out of scope for this, but maybe worth a ticket?

}

func generateTLSCertPath(id dataplane.TLSCertID) string {
return "/etc/nginx/secrets/" + string(id) + ".pem"
Copy link
Contributor

Choose a reason for hiding this comment

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

prefix is probably worth a const

for _, file := range files {
f, err := os.Create(file.Path)
if err != nil {
return fmt.Errorf("failed to create server config %s: %w", file.Path, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("failed to create server config %s: %w", file.Path, err)
return fmt.Errorf("failed to create file %s: %w", file.Path, err)


_, err = f.Write(file.Content)
if err != nil {
return fmt.Errorf("failed to write server config %s: %w", file.Path, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("failed to write server config %s: %w", file.Path, err)
return fmt.Errorf("failed to write file %s: %w", file.Path, err)

@kate-osborn
Copy link
Contributor

@pleshakov approach looks good to me. Nice work simplifying the relationship capturing 👍

@pleshakov
Copy link
Contributor Author

closing this in favor of a new non-draft PR

@pleshakov pleshakov closed this Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants