generated from operate-first/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ready For Review: in response to Automate Onboarding to Cluster via CLI
#24 (#44) * Kustomize model changes, kustomize util changes, and related other model, api, api/testdata and go mod/sum changes * Onboard related model, constant, cmd, api, and api/testdata changes or additions * Documentation and Administrative changes (README.md and OWNERS)
- Loading branch information
1 parent
a789dbd
commit 460b3e2
Showing
84 changed files
with
1,903 additions
and
206 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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.