Skip to content
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

Add project type to support hybrids SDK projects #1171

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/init_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest keep this flag hidden from the users until it's ready.
You can achieve that with cmd.Flags().MarkHidden("flag name")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍


// hiding type since the kubebuilder just works with go so far.
cmd.Flags().MarkHidden("type")
}

func (o *projectOptions) initializeProject() {
Expand Down Expand Up @@ -182,6 +186,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 `json:"resources,omitempty"`

//Define the type of the project to support SDK hybrid
ProjectType string `json:"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 @@
domain: testproject.org
repo: project
type: go
version: "1"
1 change: 1 addition & 0 deletions testdata/project-v2/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ resources:
- group: crew
kind: Admiral
version: v1
type: go
version: "2"