Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
Allow users to provide a Registry URL for storing images (#24)
Browse files Browse the repository at this point in the history
* Initial commit - basic infrastructure.

* Update to reflect the new location of kubectl/util/templates.

* Start of generating Secrets.

Co-Authored-By: Ishita Sequeira <isequeir@redhat.com>

* Include basic driver script.

This is not intended for final use, but as a way to test out the generated resources.

Co-authored-by: Ishita Sequeira <isequeir@redhat.com>

* Rename the functions to make them package private.

* implement tekton checks  Co-authorized-by Ishita Sequelira <isequeir@redhat.com>

* incoporate reiview feedbacks

* pass array of crd name strings

* Restructure code and add unit test

Co-authored-by: Ishita Sequelira  <isequeir@redhat.com>

* Kill commented import

Co-authored-by: Ishita Sequelira  <isequeir@redhat.com>

* Add eventlistener and route

- Added functions and unit tests to generate eventlistener
- Added functions and unit tests to generate route
- Appended the generated eventlistener and route to outputs slice.

* Import dependency for pipeline v1alpha1

- Imported v1alpha1 using glide get --strip-vendor

* Replace github repo name in filter string

- Used fmt.Sprintf() to replace the repo name in filter

* Rename baseRepo param to githubRepo param

* fix typos, rename interface, use t.Efrror in table test

* add error wrapping to errors returned by apis

* Delete pipelines

Delete accidentally added binary

* Add functions to generate Tekton task objects

- Added functions and test cases to create
1) deploy-from-source-task
2) deploy-using-kubectl-task
3) github-status-task

Co-Authored-By: Gagan Hegde <ghegde@redhat.com>

* initial commit for Gagan

Co-authored-by:  gaganeggday <ghegde@redhat.com>

* initial sumibt oc_adm.go, clean up service bindings.go

* rename format parameter name to avoid name collision

* polish up oc_adm.go and add unit test

* Add cluster role "edit" creation

Co-authored-by: Gagan Hegde <ghegde@redhat.com>

* Replace objects in task_tests with suitable assertive functions

- Removed stuttering function names in tasks,routes and eventlisteners package.
- Objects in task_tests are replaced by functions to improve readability.

* create functions and get rid of the block comments

* incorporate review feedbacks

* rename formal arguments from xxxName to name

* Add secret name as parameter to Generate function

* pass ServiceAccount as object to createRoleBinding

* pass ServiceAccount as object to createRoleBinding

* Drive generation of the YAML for setting up the cluster (#11)

*  added two flags github-token and quay-io-auth-json

* made changes in the flag description quayIOAuthFileName

* added logic to get the github token filename and auth.json file name

* made the requested changes mentioned in the PR

* made the requested changes mentioned in the PR and removed the unwanted comments

* created 4 required-flags quay-username, github-token, dockerconfigjson,base-repository

* Update test cases for creating opaque secret

* made the required changes mentioned in the PR

*  added two flags github-token and quay-io-auth-json

* Add functions to generate Tekton task objects

- Added functions and test cases to create
1) deploy-from-source-task
2) deploy-using-kubectl-task
3) github-status-task

Co-Authored-By: Gagan Hegde <ghegde@redhat.com>

* made changes in the flag description quayIOAuthFileName

* added logic to get the github token filename and auth.json file name

made the requested changes mentioned in the PR

made the requested changes mentioned in the PR and removed the unwanted comments

created 4 required-flags quay-username, github-token, dockerconfigjson,base-repository

Update test cases for creating opaque secret

made the required changes mentioned in the PR

* Replace objects in task_tests with suitable assertive functions

- Removed stuttering function names in tasks,routes and eventlisteners package.
- Objects in task_tests are replaced by functions to improve readability.

* Add secret name as parameter to Generate function

* pass ServiceAccount as object to createRoleBinding

* pass ServiceAccount as object to createRoleBinding

* Rework the new code around the base branch.

Explicitly marshal the yaml to os.Stdout for now.

Co-Authored-By: ishitasequeira <isequeir@redhat.com>

* made the required changes mentioned in the PR

* removed the functions which were not required from bootstrap.go

* removed the unwanted test case from bootstrap.go

* Added the test file < odo/pkg/pipelines/bootstrap_test.go>

* Test case corrected and moved to < /pkg/odo/cli/pipelines/bootstrap_test.go>

* made all the changes asked in PR

* pass a signel struct to Bootstrap()

Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Co-authored-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
Co-authored-by: gaganeggday <48808456+gaganeggday@users.noreply.github.com>
Co-authored-by: Kevin McDermott <bigkevmcd@gmail.com>

* add image-repo flag to pipeline bootstrap

* pass slice of key/value pairs instead of strings (#13)

* minor flag rename, update description (#12)

* improve tests

* Add initial namespace creation logic. (#8)

This generates the names for the namespaces and provides them when generating the resources.

Co-authored-by: William Tam <wtam@redhat.com>

* Add Buildah to the list of existing tasks (#14)

* Add functions to generate buildah task

- Added functions to generate buildah task object
- Added test cases for the corresponding functions

* Replaced steps object by steps assertive functions

* Fix typo in tasks_tests file

Co-authored-by: William Tam <wtam@redhat.com>

* Gitops issue 39 (#16)

* added pipeline.go

* added pipeline_test.go

* added cd pipeline yaml

* updated bootstrap

* upadated deployment path in bootstrap

* add deployment-path flag, called from bootstrap driver, fixed a bunch of other things

Co-authored-by: William Tam <wtam@redhat.com>

* Add function to validate image registry URL

* Issue 40: Add functions to generate trigger templates and bindings (#15)

* Refactor the bindings functions in triggers package

- Using v1alpha1 package instead of v1alpha2
- Renamed createTypeMeta() to createTriggerBindingMeta()
- Added test case for createBindingParam()
- Using Fatalf() instead of Errorf()

* template

* Barebones of test working.

* templates-test

* created go file to generate Templates

* Add generated trigger templates and bindings to outputs slice

Co-Authored-By: Dhanashri Palodkar <dpalodka@redhat.com>

* Merge templates and bindings functions into a single package

Co-Authored-By: Dhanashri Palodkar <dpalodka@redhat.com>

* Add namespaces to TriggerBindings TriggerTemplates.

Co-authored-by: Kevin McDermott <bigkevmcd@gmail.com>
Co-authored-by: Dhanashri Palodkar <dpalodkar14@gmail.com>
Co-authored-by: William Tam <wtam@redhat.com>

* Fix dockerconfigjson secret namespace and name swap issue. Move sources to func in main driver. (#17)

* Issue 53: Add flag to bypass Tekton installation checks. (#19)

* Add flag to bypass Tekton installation checks

- Added a flag --bypass-checks to bypass installation checks
- Added unit test case

* Rename BypassChecks to SkipChecks

Co-authored-by: William Tam <wtam@redhat.com>

*  Changed the service account name from demo-sa to pipeline to run tas… (#18)

*  Changed the service account name from demo-sa to pipeline to run tasks without operator

*  Passed the service account name as an argument, modified test cases

* unpack  slice before appending to outputs slice, fix ns/name ordering (#20)

* Add params to dev CI pipelinerun (#21)

- Add missing parameters in dev CI pipelinerun
- Pass the image repo as parameter
- Fix typo in template name

Co-authored-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>

* add image-repo flag to pipeline bootstrap

* improve tests

* Add function to validate image registry URL

* Pass image repo name as parameter to trigger templates

Co-authored-by: William Tam <wtam@redhat.com>

* Gitops issue 44 (#22)

* added namespace for the route

*  Added the missing namespace to route yaml

* The proper function syntax and test cases were fixed

Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>

* This seems to be lost with merges

* Call t.Run() so that it prints out the test description when they fail.  Call t.Errorf so that it continue next test case even if it fails.

* Make dockerconfigson options as it is not required if internal registry is used.

* Issue 46: Add role bindings with edit access (#23)

* Add rolebindings for dev and stage namespace

Co-authored-by: ishitasequeira <isequeir@redhat.com>

* Fix dockerconfigjson secret namespace and name swap issue. Move sources to func in main driver. (#17)

* Fix dockerconfigjson secret namespace and name swap issue. Move sources to func in main driver. (#17)

Co-authored-by: ishitasequeira <isequeir@redhat.com>

* made changes mentioned in the PR
renamed devRoleBindingName and stageRoleBindingName and created rolebindings

Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Co-authored-by: William Tam <wtam@redhat.com>

* Updated quay-username flag as optional

- Modified bootstrap script to use internal registry

* Update bootstrap command to support internal registry

- quay-username and dockerconfigjson flags are made optional
- Updated TLS for buildah task
- Added rolebinding to access internal registry

 Co-authored-by: William Tam <email.wtam@gmail.com>

* Some cleanup

* * Add optional flag to provide internal regiistry hostname with default to "image-registry.openshift-image-registry.svc:5000"
* Combine validateImageRepos() and checkInternalRegistry()
* Accept internal registry repo to be entered with registry hostname
* Reconize quay.io and docker.io registry and validate to have right number of url components.

* Check for namespace existence in internal registry URL

- Check if the internal registry namespace exists
- If not,create the required namespace

Co-authored-by: William Tam <email.wtam@gmail.com>

* Gitops issue 48 (#25)

* removed the create-github-status-task

*  Completely removed the dependency on Github-status-task

* removed the create-github-status-task and  dependency on it

Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>

* * Fixed typos
* Got rid of quay-username flag.   We don't need it now that we have image repo
* Renamed quayAuthFileName to dockerConfigJSONFileName
* Check for dockerConfigJson option after we parse image repo and know it is not an internal registry
* Fixed comments
* Add check for white spaces in image repo URL

* Issue 46: Add role bindings with edit access (#23)

* Add rolebindings for dev and stage namespace

Co-authored-by: ishitasequeira <isequeir@redhat.com>

* Fix dockerconfigjson secret namespace and name swap issue. Move sources to func in main driver. (#17)

* Fix dockerconfigjson secret namespace and name swap issue. Move sources to func in main driver. (#17)

Co-authored-by: ishitasequeira <isequeir@redhat.com>

* made changes mentioned in the PR
renamed devRoleBindingName and stageRoleBindingName and created rolebindings

Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Co-authored-by: William Tam <wtam@redhat.com>

* * Renamed BootstrapOptions to BootstrapParameters which could contain both optional and required parameters.
* Created imageRepoValidationError()

* fix  typos and comments

Co-authored-by: Kevin McDermott <bigkevmcd@gmail.com>
Co-authored-by: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com>
Co-authored-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
Co-authored-by: gaganeggday <48808456+gaganeggday@users.noreply.github.com>
Co-authored-by: Dhanashri Palodkar <dpalodkar14@gmail.com>
  • Loading branch information
6 people committed May 15, 2020
1 parent 40344d3 commit 7c3e9f6
Show file tree
Hide file tree
Showing 18 changed files with 491 additions and 211 deletions.
1 change: 0 additions & 1 deletion glide.lock

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

64 changes: 34 additions & 30 deletions pkg/odo/cli/pipelines/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,39 @@ var (
bootstrapShortDesc = `Bootstrap pipelines`
)

// BootstrapOptions encapsulates the options for the odo pipelines bootstrap
// BootstrapParameters encapsulates the paratmeters for the odo pipelines bootstrap
// command.
type BootstrapOptions struct {
deploymentPath string
quayUsername string
gitRepo string // e.g. tekton/triggers
prefix string // used to generate the environments in a shared cluster
githubToken string
quayIOAuthFilename string
skipChecks bool
type BootstrapParameters struct {
deploymentPath string
githubToken string
gitRepo string // e.g. tekton/triggers
imageRepo string
internalRegistryHostname string
prefix string // used to generate the environments in a shared cluster
dockerConfigJSONFileName string
skipChecks bool
// generic context options common to all commands
*genericclioptions.Context
}

// NewBootstrapOptions bootstraps a BootstrapOptions instance.
func NewBootstrapOptions() *BootstrapOptions {
return &BootstrapOptions{}
// NewBootstrapParameters bootstraps a BootstrapParameters instance.
func NewBootstrapParameters() *BootstrapParameters {
return &BootstrapParameters{}
}

// Complete completes BootstrapOptions after they've been created.
// Complete completes BootstrapParameters after they've been created.
//
// If the prefix provided doesn't have a "-" then one is added, this makes the
// generated environment names nicer to read.
func (bo *BootstrapOptions) Complete(name string, cmd *cobra.Command, args []string) error {
func (bo *BootstrapParameters) Complete(name string, cmd *cobra.Command, args []string) error {
if bo.prefix != "" && !strings.HasSuffix(bo.prefix, "-") {
bo.prefix = bo.prefix + "-"
}
return nil
}

// Validate validates the parameters of the BootstrapOptions.
func (bo *BootstrapOptions) Validate() error {
// Validate validates the parameters of the BootstrapParameters.
func (bo *BootstrapParameters) Validate() error {
// TODO: this won't work with GitLab as the repo can have more path elements.
if len(strings.Split(bo.gitRepo, "/")) != 2 {
return fmt.Errorf("repo must be org/repo: %s", bo.gitRepo)
Expand All @@ -65,22 +66,24 @@ func (bo *BootstrapOptions) Validate() error {
}

// Run runs the project bootstrap command.
func (bo *BootstrapOptions) Run() error {
options := pipelines.BootstrapOptions{
DeploymentPath: bo.deploymentPath,
GithubToken: bo.githubToken,
GitRepo: bo.gitRepo,
Prefix: bo.prefix,
QuayAuthFileName: bo.quayIOAuthFilename,
QuayUserName: bo.quayUsername,
SkipChecks: bo.skipChecks,
func (bo *BootstrapParameters) Run() error {
options := pipelines.BootstrapParameters{
DeploymentPath: bo.deploymentPath,
GithubToken: bo.githubToken,
GitRepo: bo.gitRepo,
ImageRepo: bo.imageRepo,
InternalRegistryHostname: bo.internalRegistryHostname,
Prefix: bo.prefix,
DockerConfigJSONFileName: bo.dockerConfigJSONFileName,
SkipChecks: bo.skipChecks,
}

return pipelines.Bootstrap(&options)
}

// NewCmdBootstrap creates the project bootstrap command.
func NewCmdBootstrap(name, fullName string) *cobra.Command {
o := NewBootstrapOptions()
o := NewBootstrapParameters()

bootstrapCmd := &cobra.Command{
Use: name,
Expand All @@ -93,16 +96,17 @@ func NewCmdBootstrap(name, fullName string) *cobra.Command {
}

bootstrapCmd.Flags().StringVarP(&o.prefix, "prefix", "p", "", "add a prefix to the environment names")
bootstrapCmd.Flags().StringVar(&o.quayUsername, "quay-username", "", "image registry username")
bootstrapCmd.MarkFlagRequired("quay-username")
bootstrapCmd.Flags().StringVar(&o.githubToken, "github-token", "", "provide the Github token")
bootstrapCmd.MarkFlagRequired("github-token")
bootstrapCmd.Flags().StringVar(&o.quayIOAuthFilename, "dockerconfigjson", "", "Docker configuration json filename")
bootstrapCmd.MarkFlagRequired("dockerconfigjson")
bootstrapCmd.Flags().StringVar(&o.dockerConfigJSONFileName, "dockerconfigjson", "", "Docker configuration json filename")
bootstrapCmd.Flags().StringVar(&o.gitRepo, "git-repo", "", "git repository in this form <username>/<repository>")
bootstrapCmd.MarkFlagRequired("git-repo")
bootstrapCmd.Flags().StringVar(&o.imageRepo, "image-repo", "", "image repository in this form <registry>/<username>/<repository> or <project>/<app> for internal registry")
bootstrapCmd.MarkFlagRequired("image-repo")
bootstrapCmd.Flags().StringVar(&o.deploymentPath, "deployment-path", "", "deployment folder path name")
bootstrapCmd.MarkFlagRequired("deployment-path")
bootstrapCmd.Flags().BoolVarP(&o.skipChecks, "skip-checks", "b", false, "skip Tekton installation checks")
bootstrapCmd.Flags().StringVar(&o.internalRegistryHostname, "internal-registry-hostname", "image-registry.openshift-image-registry.svc:5000", "internal image registry hostname")

return bootstrapCmd
}
58 changes: 34 additions & 24 deletions pkg/odo/cli/pipelines/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type keyValuePair struct {
value string
}

func TestCompleteBootstrapOptions(t *testing.T) {
func TestCompleteBootstrapParameters(t *testing.T) {
completeTests := []struct {
name string
prefix string
Expand All @@ -25,7 +25,7 @@ func TestCompleteBootstrapOptions(t *testing.T) {
}

for _, tt := range completeTests {
o := BootstrapOptions{prefix: tt.prefix}
o := BootstrapParameters{prefix: tt.prefix}

err := o.Complete("test", &cobra.Command{}, []string{"test", "test/repo"})

Expand All @@ -39,7 +39,7 @@ func TestCompleteBootstrapOptions(t *testing.T) {
}
}

func TestValidateBootstrapOptions(t *testing.T) {
func TestValidateBootstrapParameters(t *testing.T) {
optionTests := []struct {
name string
gitRepo string
Expand All @@ -50,7 +50,7 @@ func TestValidateBootstrapOptions(t *testing.T) {
}

for _, tt := range optionTests {
o := BootstrapOptions{quayUsername: "testing", gitRepo: tt.gitRepo, prefix: "test"}
o := BootstrapParameters{gitRepo: tt.gitRepo, prefix: "test"}

err := o.Validate()

Expand All @@ -64,25 +64,33 @@ func TestValidateBootstrapOptions(t *testing.T) {
}
}
}

func TestBootstrapCommandWithMissingParams(t *testing.T) {
cmdTests := []struct {
desc string
flags []keyValuePair
wantErr string
}{
{[]keyValuePair{flag("quay-username", "example"), flag("github-token", "abc123"), flag("dockerconfigjson", "~/"),
flag("deployment-path", "foo")}, `Required flag(s) "git-repo" have/has not been set`},
{[]keyValuePair{flag("quay-username", "example"), flag("github-token", "abc123"), flag("git-repo", "example/repo"),
flag("deployment-path", "foo")}, `Required flag(s) "dockerconfigjson" have/has not been set`},
{[]keyValuePair{flag("quay-username", "example"), flag("dockerconfigjson", "~/"), flag("git-repo", "example/repo"),
flag("deployment-path", "foo")}, `Required flag(s) "github-token" have/has not been set`},
{[]keyValuePair{flag("github-token", "abc123"), flag("dockerconfigjson", "~/"), flag("git-repo", "example/repo"),
flag("deployment-path", "foo")}, `Required flag(s) "quay-username" have/has not been set`},
{"Missing git-repo flag",
[]keyValuePair{flag("github-token", "abc123"),
flag("dockerconfigjson", "~/"), flag("image-repo", "foo/bar/bar"), flag("deployment-path", "foo")},
`Required flag(s) "git-repo" have/has not been set`},
{"Missing github-token flag",
[]keyValuePair{flag("dockerconfigjson", "~/"),
flag("git-repo", "example/repo"), flag("image-repo", "foo/bar/bar"), flag("deployment-path", "foo")},
`Required flag(s) "github-token" have/has not been set`},
{"Missing image-repo",
[]keyValuePair{flag("github-token", "abc123"),
flag("dockerconfigjson", "~/"), flag("git-repo", "example/repo"), flag("deployment-path", "foo")},
`Required flag(s) "image-repo" have/has not been set`},
}
for _, tt := range cmdTests {
_, _, err := executeCommand(NewCmdBootstrap("bootstrap", "odo pipelines bootstrap"), tt.flags...)
if err.Error() != tt.wantErr {
t.Errorf("got %s, want %s", err, tt.wantErr)
}
t.Run(tt.desc, func(t *testing.T) {
_, _, err := executeCommand(NewCmdBootstrap("bootstrap", "odo pipelines bootstrap"), tt.flags...)
if err.Error() != tt.wantErr {
t.Errorf("got %s, want %s", err, tt.wantErr)
}
})
}
}

Expand All @@ -97,17 +105,19 @@ func TestBypassChecks(t *testing.T) {
}

for _, test := range tests {
o := BootstrapOptions{skipChecks: test.skipChecks}
t.Run(test.description, func(t *testing.T) {
o := BootstrapParameters{skipChecks: test.skipChecks}

err := o.Complete("test", &cobra.Command{}, []string{"test", "test/repo"})
err := o.Complete("test", &cobra.Command{}, []string{"test", "test/repo"})

if err != nil {
t.Errorf("Complete() %#v failed: ", err)
}
if err != nil {
t.Errorf("Complete() %#v failed: ", err)
}

if o.skipChecks != test.wantedBypassChecks {
t.Errorf("Complete() %#v bypassChecks flag: got %v, want %v", test.description, o.skipChecks, test.wantedBypassChecks)
}
if o.skipChecks != test.wantedBypassChecks {
t.Errorf("Complete() %#v bypassChecks flag: got %v, want %v", test.description, o.skipChecks, test.wantedBypassChecks)
}
})
}

}
Expand Down
Loading

0 comments on commit 7c3e9f6

Please sign in to comment.