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

Add acceptance test for bug #810 and update how secret names are generated #1066

Merged
merged 10 commits into from Nov 15, 2021

Conversation

jrryjcksn
Copy link
Contributor

@jrryjcksn jrryjcksn commented Nov 11, 2021

Closes: #810

What changed?

  • Added acceptance test that creates multiple clusters and deploys an app from a single repository to both clusters
  • Updated how secret names are generated (removed cluster name and added git provider name)

In the past, we attempted to remove deploy keys that were no longer being used so we included the cluster name in the deploy key name (allowing the deploy key for a single cluster to be removed while leaving others intact). We no longer remove deploy keys and all generated deploy keys have the same name: wego-deploy-key. The name genericizing (generification?) process was never extended to the secret names themselves, however, which still included cluster names. This caused no problems until we started trying to deploy an application into multiple clusters from the same repository. Initial testing of the multi-cluster scenario used two applications in the same repository (one with path ./ and one with another path). This worked because the applications did not share automation manifests. With a single application, though, we only have one copy of each automation manifest and a GitRepository manifest for a private repository contains a name reference to the secret. If the secret name includes the cluster name, deployment to one of the clusters will fail as the GitRepository manifest will have one or the other secret name. This PR removes the cluster name from a generated secret name.

Why?
To allow a single application to be deployed to multiple clusters from a common source repository.

How did you test it?
Manual tests and new acceptance test

Release notes
No, since we don't currently claim to support multi-cluster

Documentation Changes
No, since we don't discuss the secrets in the current documentation.

@jrryjcksn jrryjcksn self-assigned this Nov 11, 2021
@jrryjcksn jrryjcksn added the type/enhancement New feature or request label Nov 11, 2021
@jrryjcksn jrryjcksn force-pushed the add-integration-test-for-multi-cluster-app-bug-810 branch from 9268655 to 002c369 Compare November 12, 2021 16:20
@jrryjcksn jrryjcksn marked this pull request as ready for review November 12, 2021 18:51
@@ -268,7 +268,7 @@ var _ = Describe("Add Gitlab", func() {
Expect(name).To(Equal("bar"))
Expect(url.String()).To(Equal("ssh://git@gitlab.com/foo/bar.git"))
Expect(branch).To(Equal("main"))
Expect(secretRef).To(Equal("wego-test-cluster-bar"))
Expect(secretRef).To(Equal("wego-gitlab-bar"))
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

func CreateRepoSecretName(targetName string, gitSourceURL gitproviders.RepoURL) GeneratedSecretName {
return GeneratedSecretName(hashNameIfTooLong(fmt.Sprintf("wego-%s-%s", targetName, GenerateResourceName(gitSourceURL))))
func CreateRepoSecretName(gitSourceURL gitproviders.RepoURL) GeneratedSecretName {
return GeneratedSecretName(hashNameIfTooLong(fmt.Sprintf("wego-%s-%s", string(gitSourceURL.Provider()), replaceUnderscores(gitSourceURL.RepositoryName()))))
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 This is getting a little tough to read. Can we break this up with some variable names to demystify it a bit:

Suggested change
return GeneratedSecretName(hashNameIfTooLong(fmt.Sprintf("wego-%s-%s", string(gitSourceURL.Provider()), replaceUnderscores(gitSourceURL.RepositoryName()))))
provder := gitSourceURL.Provider()
cleanRepoName := replaceUnderscores(gitSourceURL.RepositoryName())
baseName := fmt.Sprintf("wego-%s-%s", provider, cleanRepoName)
nameOrHash := hashNameIfTooLong(baseName)
return GeneratedSecretName(nameOrHash)

Not terribly elegant but it might make it easier to understand what's happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

@jrryjcksn jrryjcksn merged commit d6ef1ea into main Nov 15, 2021
@jrryjcksn jrryjcksn deleted the add-integration-test-for-multi-cluster-app-bug-810 branch November 15, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
2 participants