diff --git a/cmd/init_project.go b/cmd/init_project.go index 689ca8fd5c9..842b60e25b9 100644 --- a/cmd/init_project.go +++ b/cmd/init_project.go @@ -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") + + // hiding type since the kubebuilder just works with go so far. + cmd.Flags().MarkHidden("type") } func (o *projectOptions) initializeProject() { @@ -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 } diff --git a/pkg/scaffold/input/input.go b/pkg/scaffold/input/input.go index ebb8c940557..a08b5b0611c 100644 --- a/pkg/scaffold/input/input.go +++ b/pkg/scaffold/input/input.go @@ -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 } @@ -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. diff --git a/pkg/scaffold/project/project.go b/pkg/scaffold/project/project.go index 4a706bdcc55..df2fd659cc5 100644 --- a/pkg/scaffold/project/project.go +++ b/pkg/scaffold/project/project.go @@ -35,7 +35,6 @@ var _ input.File = &Project{} type Project struct { // Path is the output file location - defaults to PROJECT Path string - input.ProjectFile } @@ -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") } @@ -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 diff --git a/pkg/scaffold/project/type.go b/pkg/scaffold/project/type.go new file mode 100644 index 00000000000..c7b45c7fe09 --- /dev/null +++ b/pkg/scaffold/project/type.go @@ -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 +} diff --git a/testdata/gopath/src/project/PROJECT b/testdata/gopath/src/project/PROJECT index 9ee326caba7..77d88d55d06 100644 --- a/testdata/gopath/src/project/PROJECT +++ b/testdata/gopath/src/project/PROJECT @@ -1,3 +1,4 @@ domain: testproject.org repo: project +type: go version: "1" diff --git a/testdata/project-v2/PROJECT b/testdata/project-v2/PROJECT index 36aacd80d5b..c8dd5bc1c87 100644 --- a/testdata/project-v2/PROJECT +++ b/testdata/project-v2/PROJECT @@ -10,4 +10,5 @@ resources: - group: crew kind: Admiral version: v1 +type: go version: "2"