generated from operate-first/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Ready For Review: in response to Automate Onboarding to Cluster via CLI #24 #44
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
Merged
sesheta
merged 3 commits into
operate-first:main
from
Gregory-Pereira:automated-releases
Mar 24, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3459398
Kustomize model changes, kustomize util changes, and related other mo…
Gregory-Pereira 40dcaec
Onboard related model, constant, cmd, api, and api/testdata changes o…
Gregory-Pereira 063a4cf
Documentation and Administrative changes (README.md and OWNERS)
Gregory-Pereira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ approvers: | |
| - durandom | ||
| - tumido | ||
| - HumairAK | ||
| - Gregory-Pereira | ||
|
|
||
| reviewers: | ||
| - hemajv | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| // "fmt" | ||
|
|
||
| "fmt" | ||
| "io/ioutil" | ||
| "path/filepath" | ||
|
|
||
| "github.com/operate-first/opfcli/constants" | ||
| "github.com/operate-first/opfcli/models" | ||
| "github.com/operate-first/opfcli/utils" | ||
| log "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| func (api *API) CreateCustomResourceQuota(namespace string, customResourceQuota models.CustomResourceQuota, existsOk bool) error { | ||
| path := filepath.Join( | ||
| api.RepoDirectory, api.AppName, | ||
| constants.NamespacePath, namespace, "resourcequota.yaml", | ||
| ) | ||
|
|
||
| exists, err := utils.PathExists(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if exists { | ||
| if existsOk { | ||
| log.Warnf("custom resource for namespace %s already exists (continuing)", namespace) | ||
| return nil | ||
| } | ||
| return fmt.Errorf("resource quota already exists in namespace %s", namespace) | ||
| } | ||
| customResource := models.NewCustomResourceQuota(namespace, customResourceQuota) | ||
| customResourceOut, err := models.ToYAML(customResource) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| log.Printf("writing ResourceQuota definition to %s", filepath.Dir(path)) | ||
| if exist, err := utils.PathExists(filepath.Dir(path)); err != nil || !exist { | ||
| if exist { | ||
| return fmt.Errorf("error writing resource quota. error: %s", err) | ||
| } | ||
| return fmt.Errorf("directory should already have been created for the namespace. directory %s does not exist", namespace) | ||
| } | ||
|
|
||
| err = ioutil.WriteFile(path, customResourceOut, 0644) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to write resource quota file: %w", err) | ||
| } | ||
|
|
||
| err = utils.AddKustomizeResources(filepath.Dir(path), []string{"resourcequota.yaml"}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to append ResourceQuota resource to kustomization file") | ||
| } | ||
|
|
||
| return nil | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/operate-first/opfcli/constants" | ||
| "github.com/operate-first/opfcli/models" | ||
| "github.com/operate-first/opfcli/utils" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func (suite *apiTestSuite) TestCreateCustomResourceQuota() { | ||
| assert := require.New(suite.T()) | ||
| path := filepath.Join( | ||
| suite.api.RepoDirectory, suite.api.AppName, | ||
| constants.NamespacePath, "testproject", "kustomization.yaml", | ||
| ) | ||
| // should fail if no namespace is present when attempting to append the kustomization | ||
| err := suite.api.CreateCustomResourceQuota("test", models.CustomResourceQuota{}, true) | ||
| assert.EqualError(err, "directory should already have been created for the namespace. directory test does not exist") | ||
|
|
||
| // creates namespace directory | ||
| err = os.MkdirAll(filepath.Dir(path), 0755) | ||
| assert.Nil(err) | ||
|
|
||
| // should fail because kustomization file in namespace directory does not exist, and so cannot append resource quota value to it | ||
| err = suite.api.CreateCustomResourceQuota("testproject", models.CustomResourceQuota{}, true) | ||
| assert.EqualError(err, "failed to append ResourceQuota resource to kustomization file") | ||
|
|
||
| // should succeed | ||
| kustom := models.NewKustomization([]string{"namespace.yaml"}, []string{"../../../../components/limitranges/default", "../../../../components/project-admin-rolebindings/testgroup"}, "testgroup") | ||
| err = utils.WriteKustomization(filepath.Dir(path), kustom) | ||
| assert.Nil(err) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.