Skip to content

Commit

Permalink
Add profiles.yaml to Kustomization for system/ dir
Browse files Browse the repository at this point in the history
- Improve acceptance test for Profiles service
- Improve logic for creating kind clusters to avoid duplicate prefix e.g. kind-kind-x
  • Loading branch information
nikimanoledaki committed Jan 28, 2022
1 parent c6d0078 commit aaaa875
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 80 deletions.
8 changes: 4 additions & 4 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const WegoClusterOSWorkloadDir = "system"
// WegoClusterUserWorkloadDir is where user workload manifests will live in the GitOps repo
const WegoClusterUserWorkloadDir = "user"

// ManifestFileName contains the manifests of all installed Profiles
const ManifestFileName = "profiles.yaml"
// ProfilesManifestFileName contains the manifests of all installed Profiles
const ProfilesManifestFileName = "profiles.yaml"

func getClusterPath(clusterName string) string {
return filepath.Join(WegoRoot, WegoClusterDir, clusterName)
Expand All @@ -77,10 +77,10 @@ func GetSystemQualifiedPath(clusterName string, relativePath string) string {
return filepath.Join(GetSystemPath(clusterName), relativePath)
}

// GetProfilesPath returns the path of the file containing the manifests of installed Profile manifests
// GetProfilesPath returns the path of the file containing the manifests of installed Profiles
// joined with the cluster's system directory
func GetProfilesPath(clusterName string) string {
return filepath.Join(GetSystemPath(clusterName), ManifestFileName)
return filepath.Join(GetSystemPath(clusterName), ProfilesManifestFileName)
}

// Git is an interface for basic Git operations on a single branch of a
Expand Down
3 changes: 2 additions & 1 deletion pkg/models/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
SystemKustomizationPath = "kustomization.yaml"
WegoAppPath = "wego-app.yaml"
WegoConfigPath = "wego-config.yaml"
WegoProfilePath = "profiles.yaml"

WegoConfigMapName = "weave-gitops-config"
)
Expand Down Expand Up @@ -151,7 +152,7 @@ type GitopsManifestsParams struct {

// GitopsManifests generates all yaml files that are going to be written in the config repo
func GitopsManifests(ctx context.Context, bootstrapManifests []Manifest, params GitopsManifestsParams) ([]Manifest, error) {
systemKustomization := CreateKustomization(params.ClusterName, params.WegoNamespace, RuntimePath, SourcePath, SystemKustResourcePath, UserKustResourcePath, WegoAppPath)
systemKustomization := CreateKustomization(params.ClusterName, params.WegoNamespace, RuntimePath, SourcePath, SystemKustResourcePath, UserKustResourcePath, WegoAppPath, WegoProfilePath)

systemKustomizationManifest, err := yaml.Marshal(systemKustomization)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var _ = Describe("Installer", func() {

fakeGitProvider.GetDefaultBranchReturns("main", nil)

systemKustomization := CreateKustomization(params.ClusterName, params.WegoNamespace, RuntimePath, SourcePath, SystemKustResourcePath, UserKustResourcePath, WegoAppPath)
systemKustomization := CreateKustomization(params.ClusterName, params.WegoNamespace, RuntimePath, SourcePath, SystemKustResourcePath, UserKustResourcePath, WegoAppPath, WegoProfilePath)

systemKustomizationManifest, err := yaml.Marshal(systemKustomization)
Expect(err).ShouldNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/install/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ var _ = Describe("Installer", func() {
wegoConfigManifest, err = yaml.Marshal(gitopsConfigMap)
Expect(err).ShouldNot(HaveOccurred())

systemKustomization := models.CreateKustomization(clusterName, testNamespace, models.RuntimePath, models.SourcePath, models.SystemKustResourcePath, models.UserKustResourcePath, models.WegoAppPath)
systemKustomization := models.CreateKustomization(clusterName, testNamespace, models.RuntimePath, models.SourcePath, models.SystemKustResourcePath, models.UserKustResourcePath, models.WegoAppPath, models.WegoProfilePath)

systemKustomizationManifest, err = yaml.Marshal(systemKustomization)
Expect(err).ShouldNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/profiles/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *ProfilesSvc) Add(ctx context.Context, gitProvider gitproviders.GitProvi
s.Logger.Actionf("Pull Request created: %s", pr.Get().WebURL)

if opts.AutoMerge {
s.Logger.Actionf("auto-merge=true; merging PR number %s", pr.Get().Number)
s.Logger.Actionf("auto-merge=true; merging PR number %v", pr.Get().Number)
if err := gitProvider.MergePullRequest(ctx, configRepoUrl, pr.Get().Number, gitprovider.MergeMethodMerge, AddCommitMessage); err != nil {
return err
}
Expand Down
48 changes: 24 additions & 24 deletions pkg/services/profiles/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ var _ = Describe("Add", func() {
})

When("auto-merge is enabled", func() {
It("merges the PR that was created", func() {
JustBeforeEach(func() {
gitProviders.RepositoryExistsReturns(true, nil)
gitProviders.GetDefaultBranchReturns("main", nil)
gitProviders.GetRepoFilesReturns(makeTestFiles(), nil)
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
return true, newFakeResponseWrapper(getProfilesResp), nil
})
})

It("merges the PR that was created", func() {
fakePR.GetReturns(gitprovider.PullRequestInfo{
WebURL: "url",
Number: 42,
Expand All @@ -85,12 +88,7 @@ var _ = Describe("Add", func() {

When("the PR fails to be merged", func() {
It("returns an error", func() {
gitProviders.RepositoryExistsReturns(true, nil)
gitProviders.GetDefaultBranchReturns("main", nil)
gitProviders.GetRepoFilesReturns(makeTestFiles(), nil)
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
return true, newFakeResponseWrapper(getProfilesResp), nil
})

fakePR.GetReturns(gitprovider.PullRequestInfo{
WebURL: "url",
})
Expand Down Expand Up @@ -156,13 +154,6 @@ var _ = Describe("Add", func() {
})
})

It("fails if the given version was not found", func() {
addOptions.Version = "7.0.0"
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
Expect(err).NotTo(BeNil())
Expect(err).To(MatchError("version '7.0.0' not found for profile 'podinfo' in prod/weave-system"))
})

It("creates a helm release with that version", func() {
addOptions.Version = "6.0.0"
fakePR.GetReturns(gitprovider.PullRequestInfo{
Expand All @@ -175,20 +166,28 @@ var _ = Describe("Add", func() {
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
Expect(err).To(BeNil())
})
})

It("fails to create a pull request to write the helm release to the config repo", func() {
gitProviders.RepositoryExistsReturns(true, nil)
gitProviders.GetRepoFilesReturns(makeTestFiles(), nil)
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
return true, newFakeResponseWrapper(getProfilesResp), nil
It("fails if the given version was not found", func() {
addOptions.Version = "7.0.0"
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
Expect(err).NotTo(BeNil())
Expect(err).To(MatchError("version '7.0.0' not found for profile 'podinfo' in prod/weave-system"))
})
gitProviders.CreatePullRequestReturns(nil, fmt.Errorf("err"))
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
Expect(err).NotTo(BeNil())
Expect(err).To(MatchError("failed to create the pull request: err"))
})

When("it fails to create a pull request to write the helm release to the config repo", func() {
It("returns an error when ", func() {
gitProviders.RepositoryExistsReturns(true, nil)
gitProviders.GetRepoFilesReturns(makeTestFiles(), nil)
clientSet.AddProxyReactor("services", func(action testing.Action) (handled bool, ret restclient.ResponseWrapper, err error) {
return true, newFakeResponseWrapper(getProfilesResp), nil
})
gitProviders.CreatePullRequestReturns(nil, fmt.Errorf("err"))
err := profilesSvc.Add(context.TODO(), gitProviders, addOptions)
Expect(err).NotTo(BeNil())
Expect(err).To(MatchError("failed to create the pull request: err"))
})
})
})

var _ = Describe("MakeManifestFile", func() {
Expand Down Expand Up @@ -258,6 +257,7 @@ var _ = Describe("MakeManifestFile", func() {
})
})
})

It("fails if the manifest contains a resource that is not a HelmRelease", func() {
content = "content"
_, err := profiles.MakeManifestFile([]*gitprovider.CommitFile{{
Expand Down
167 changes: 167 additions & 0 deletions pkg/vendorfakes/fakegitprovider/pull_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aaaa875

Please sign in to comment.