Skip to content

Commit

Permalink
add type to project file to support hybrid sdk projects
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Nov 10, 2019
1 parent fe52a52 commit 53e427b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cmd/init_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (o *projectOptions) bindCmdlineFlags(cmd *cobra.Command) {
"defaults to the go package of the current working directory.")
cmd.Flags().StringVar(&o.project.Domain, "domain", "my.domain", "domain for groups")
cmd.Flags().StringVar(&o.project.Version, "project-version", project.Version2, "project version")
cmd.Flags().StringVar(&o.project.ProjectType, "type", project.Go, "project type")
}

func (o *projectOptions) initializeProject() {
Expand Down Expand Up @@ -167,6 +168,16 @@ func (o *projectOptions) validate() error {
return fmt.Errorf("unknown project version %v", o.project.Version)
}

switch o.project.ProjectType {
case project.Go:
case project.Ansible:
return fmt.Errorf("The hybrid Ansible type is not supported by kubebuilder")
case project.Helm:
return fmt.Errorf("The hybrid Helm type is not supported by kubebuilder")
default:
return fmt.Errorf("unknown project type %v", o.project.ProjectType)
}

if err := o.scaffolder.Validate(); err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/scaffold/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type Input struct {
// Repo is the go project package
Repo string

// Type is the type of project to support SDK hybrid
ProjectType string

// ProjectPath is the relative path to the project root
ProjectPath string
}
Expand Down Expand Up @@ -173,6 +176,9 @@ type ProjectFile struct {
// Resources tracks scaffolded resources in the project. This info is
// tracked only in project with version 2.
Resources []Resource `yaml:"resources,omitempty"`

//Define the type of the project to support SDK hybrid
ProjectType string `yaml:"type,omitempty"`
}

// ResourceGroups returns unique groups of scaffolded resources in the project.
Expand Down
7 changes: 6 additions & 1 deletion pkg/scaffold/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var _ input.File = &Project{}
type Project struct {
// Path is the output file location - defaults to PROJECT
Path string

input.ProjectFile
}

Expand All @@ -47,6 +46,11 @@ func (c *Project) GetInput() (input.Input, error) {
if c.Version == "" {
c.Version = Version1
}

if c.ProjectType == "" {
c.ProjectType = Go
}

if c.Repo == "" {
return input.Input{}, fmt.Errorf("must specify repository")
}
Expand All @@ -61,6 +65,7 @@ func (c *Project) GetInput() (input.Input, error) {
TemplateBody: string(out),
Repo: c.Repo,
Version: c.Version,
ProjectType: c.ProjectType,
Domain: c.Domain,
IfExistsAction: input.Error,
}, nil
Expand Down
28 changes: 28 additions & 0 deletions pkg/scaffold/project/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package project

// constants for scaffolding types
const (
Go = "go"
Ansible = "Ansible"
Helm = "Helm"
)

type Type struct {
Type string
}
1 change: 1 addition & 0 deletions testdata/gopath/src/project/PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: "1"
domain: testproject.org
repo: project
type: go
1 change: 1 addition & 0 deletions testdata/project-v2/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ resources:
- group: crew
version: v1
kind: Admiral
type: go

0 comments on commit 53e427b

Please sign in to comment.