Skip to content
Merged
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
33 changes: 33 additions & 0 deletions changelog/fragments/cmd-legacy-helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
The commands `operator-sdk new --type=helm` and `operator-sdk add api` are no longer supported for Helm-based Operators.

# kind is one of:
# - addition
# - change
# - deprecation
# - removal
# - bugfix
kind: "removal"

# Is this a breaking change?
breaking: true

# NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS
# FILE FOR A PREVIOUSLY MERGED PULL_REQUEST!
#
# The generator auto-detects the PR number from the commit
# message in which this file was originally added.
#
# What is the pull request number (without the "#")?
# pull_request_override: 0


# Migration can be defined to automatically add a section to
# the migration guide. This is required for breaking changes.
migration:
header: New and api subcommands are no longer supported for Helm-based Operators.
body: >
TBD
18 changes: 18 additions & 0 deletions changelog/fragments/remove-legacy-helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
The Helm legacy layout is no longer supported.

kind: "removal"

# Is this a breaking change?
breaking: true

# Migration can be defined to automatically add a section to
# the migration guide. This is required for breaking changes.
migration:
header: Migrate your Helm project to the new layout
body: >
TBD

59 changes: 2 additions & 57 deletions cmd/operator-sdk/add/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/operator-framework/operator-sdk/internal/genutil"
"github.com/operator-framework/operator-sdk/internal/scaffold"
"github.com/operator-framework/operator-sdk/internal/scaffold/ansible"
"github.com/operator-framework/operator-sdk/internal/scaffold/helm"
"github.com/operator-framework/operator-sdk/internal/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
)
Expand Down Expand Up @@ -54,12 +53,6 @@ For Ansible-based operators:
- Creates resource folder under /roles.
- watches.yaml is updated with new resource.
- deploy/role.yaml will be updated with apiGroup for new API.

For Helm-based operators:
- Creates resource folder under /helm-charts.
- watches.yaml is updated with new resource.
- deploy/role.yaml will be updated to reflact new rules for the incoming API.

CRD's are generated, or updated if they exist for a particular group + version + kind, under
deploy/crds/<full group>_<resource>_crd.yaml; OpenAPI V3 validation YAML
is generated as a 'validation' object.`,
Expand All @@ -71,38 +64,6 @@ is generated as a 'validation' object.`,
$ operator-sdk add api \
--api-version=app.example.com/v1alpha1 \
--kind=AppService

# Helm Example:
$ operator-sdk add api \
--api-version=app.example.com/v1alpha1 \
--kind=AppService

$ operator-sdk add api \
--api-version=app.example.com/v1alpha1 \
--kind=AppService
--helm-chart=myrepo/app

$ operator-sdk add api \
--helm-chart=myrepo/app

$ operator-sdk add api \
--helm-chart=myrepo/app \
--helm-chart-version=1.2.3

$ operator-sdk add api \
--helm-chart=app \
--helm-chart-repo=https://charts.mycompany.com/

$ operator-sdk add api \
--helm-chart=app \
--helm-chart-repo=https://charts.mycompany.com/ \
--helm-chart-version=1.2.3

$ operator-sdk add api \
--helm-chart=/path/to/local/chart-directories/app/

$ operator-sdk add api \
--helm-chart=/path/to/local/chart-archives/app-1.2.3.tgz
`,
RunE: apiRun,
}
Expand Down Expand Up @@ -131,28 +92,12 @@ func apiRun(cmd *cobra.Command, args []string) error {
switch operatorType {
case projutil.OperatorTypeGo:
return fmt.Errorf("the `add api` command is not supported for Go operators")
case projutil.OperatorTypeHelm:
return fmt.Errorf("the `add api` command is not supported for Helm operators")
case projutil.OperatorTypeAnsible:
if err := doAnsibleAPIScaffold(); err != nil {
return err
}
case projutil.OperatorTypeHelm:
absProjectPath := projutil.MustGetwd()
projectName := filepath.Base(absProjectPath)
cfg := input.Config{
AbsProjectPath: absProjectPath,
ProjectName: projectName,
}
createOpts := helm.CreateChartOptions{
ResourceAPIVersion: apiFlags.APIVersion,
ResourceKind: apiFlags.Kind,
Chart: apiFlags.HelmChartRef,
Version: apiFlags.HelmChartVersion,
Repo: apiFlags.HelmChartRepo,
CRDVersion: apiFlags.CrdVersion,
}
if err := helm.API(cfg, createOpts); err != nil {
return err
}
Comment thread
camilamacedo86 marked this conversation as resolved.
}
log.Info("API generation complete.")
return nil
Expand Down
87 changes: 5 additions & 82 deletions cmd/operator-sdk/new/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/operator-framework/operator-sdk/internal/genutil"
"github.com/operator-framework/operator-sdk/internal/scaffold"
"github.com/operator-framework/operator-sdk/internal/scaffold/ansible"
"github.com/operator-framework/operator-sdk/internal/scaffold/helm"
"github.com/operator-framework/operator-sdk/internal/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
)
Expand Down Expand Up @@ -56,46 +55,14 @@ generates a default directory layout based on the input <project-name>.
$ operator-sdk new app-operator --type=ansible \
--api-version=app.example.com/v1alpha1 \
--kind=AppService

# Helm project
$ operator-sdk new app-operator --type=helm \
--api-version=app.example.com/v1alpha1 \
--kind=AppService

$ operator-sdk new app-operator --type=helm \
--api-version=app.example.com/v1alpha1 \
--kind=AppService \
--helm-chart=myrepo/app

$ operator-sdk new app-operator --type=helm \
--helm-chart=myrepo/app

$ operator-sdk new app-operator --type=helm \
--helm-chart=myrepo/app \
--helm-chart-version=1.2.3

$ operator-sdk new app-operator --type=helm \
--helm-chart=app \
--helm-chart-repo=https://charts.mycompany.com/

$ operator-sdk new app-operator --type=helm \
--helm-chart=app \
--helm-chart-repo=https://charts.mycompany.com/ \
--helm-chart-version=1.2.3

$ operator-sdk new app-operator --type=helm \
--helm-chart=/path/to/local/chart-directories/app/

$ operator-sdk new app-operator --type=helm \
--helm-chart=/path/to/local/chart-archives/app-1.2.3.tgz
`,
RunE: newFunc,
}

newCmd.Flags().StringVar(&operatorType, "type", "",
"Type of operator to initialize (choices: \"ansible\" or \"helm\")")
if err := newCmd.MarkFlagRequired("type"); err != nil {
log.Fatalf("Failed to mark `type` flag for `new` subcommand as required")
newCmd.Flags().StringVar(&operatorType, "type", "ansible",
"Type of operator to initialize (choices: \"ansible\")")
if err := newCmd.Flags().MarkHidden("type"); err != nil {
log.Fatalf("Failed to mark `type` flag for `new` subcommand as hidden")
}

// todo(camilamacedo86): remove before 1.0.0
Expand Down Expand Up @@ -129,7 +96,7 @@ func newFunc(cmd *cobra.Command, args []string) error {
return err
}
mustBeNewProject()
if err := verifyFlags(); err != nil {
if err := apiFlags.VerifyCommonFlags(operatorType); err != nil {
return err
}

Expand All @@ -140,35 +107,6 @@ func newFunc(cmd *cobra.Command, args []string) error {
if err := doAnsibleScaffold(); err != nil {
log.Fatal(err)
}
case projutil.OperatorTypeHelm:
// create the project dir
err := os.MkdirAll(projectName, 0755)
if err != nil {
log.Fatal(err)
}
// go inside of the project dir
err = os.Chdir(filepath.Join(projutil.MustGetwd(), projectName))
if err != nil {
log.Fatal(err)
}

cfg := input.Config{
AbsProjectPath: filepath.Join(projutil.MustGetwd()),
ProjectName: projectName,
}

createOpts := helm.CreateChartOptions{
ResourceAPIVersion: apiFlags.APIVersion,
ResourceKind: apiFlags.Kind,
Chart: apiFlags.HelmChartRef,
Version: apiFlags.HelmChartVersion,
Repo: apiFlags.HelmChartRepo,
CRDVersion: apiFlags.CrdVersion,
}

if err := helm.Init(cfg, createOpts); err != nil {
log.Fatal(err)
}
}
//todo: remove before 1.0.0
if gitInit {
Expand Down Expand Up @@ -302,21 +240,6 @@ func doAnsibleScaffold() error {
return nil
}

func verifyFlags() error {
if operatorType != projutil.OperatorTypeAnsible && operatorType != projutil.OperatorTypeHelm {
return fmt.Errorf("value of --type can only be `ansible`, or `helm`: %v",
projutil.ErrUnknownOperatorType{Type: operatorType})
}
if operatorType != projutil.OperatorTypeAnsible && generatePlaybook {
return fmt.Errorf("value of --generate-playbook can only be used with --type `ansible`")
}
if err := apiFlags.VerifyCommonFlags(operatorType); err != nil {
return err
}

return nil
}

// todo(camilamacedo86): remove before 1.0.0
// Deprecated: the git-init flag was deprecated since has no need to make the command run the git init.
// users are allowed to easily do that when they wish. This func is just used here to run the git-init
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/operator-framework/api v0.3.8
github.com/operator-framework/operator-registry v1.12.6-0.20200611222234-275301b779f8
github.com/prometheus/client_golang v1.5.1
github.com/prometheus/common v0.9.1
github.com/rogpeppe/go-internal v1.5.0
github.com/sergi/go-diff v1.0.0
github.com/sirupsen/logrus v1.5.0
Expand Down
62 changes: 16 additions & 46 deletions internal/flags/apiflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ import (
"github.com/spf13/pflag"

gencrd "github.com/operator-framework/operator-sdk/internal/generate/crd"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
)

type APIFlags struct {
SkipGeneration bool
APIVersion string
Kind string
CrdVersion string
HelmChartRef string
HelmChartVersion string
HelmChartRepo string
SkipGeneration bool
APIVersion string
Kind string
CrdVersion string
}

// AddTo - Add the reconcile period and watches file flags to the the flagset
Expand All @@ -49,49 +45,23 @@ func (f *APIFlags) AddTo(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.CrdVersion, "crd-version", gencrd.DefaultCRDVersion,
"CRD version to generate")

flagSet.StringVar(&f.HelmChartRef, "helm-chart", "",
"Initialize helm operator with existing helm chart (<URL>, <repo>/<name>, or local path). Valid only for --type helm")

flagSet.StringVar(&f.HelmChartVersion, "helm-chart-version", "",
"Specific version of the helm chart (default is latest version). Valid only for --type helm")

flagSet.StringVar(&f.HelmChartRepo, "helm-chart-repo", "",
"Chart repository URL for the requested helm chart, Valid only for --type helm")

}

// VerifyCommonFlags func is used to verify flags common to both "new" and "add api" commands.
func (f *APIFlags) VerifyCommonFlags(operatorType string) error {

if len(f.HelmChartRef) != 0 {
if operatorType != projutil.OperatorTypeHelm {
return fmt.Errorf("value of --helm-chart can only be used with --type=helm")
}
} else if len(f.HelmChartRepo) != 0 {
return fmt.Errorf("value of --helm-chart-repo can only be used with --type=helm and --helm-chart")
} else if len(f.HelmChartVersion) != 0 {
return fmt.Errorf("value of --helm-chart-version can only be used with --type=helm and --helm-chart")
if len(f.APIVersion) == 0 {
return fmt.Errorf("value of --api-version must not have empty value")
}

// --api-version and --kind are required with --type=ansible, --type=helm , with one exception.
// If --type=helm and --helm-chart is set, --api-version and --kind are optional. If left unset,
// sane defaults are used when the specified helm chart is created.
if (operatorType == projutil.OperatorTypeAnsible || operatorType == projutil.OperatorTypeHelm) &&
len(f.HelmChartRef) == 0 {
if len(f.APIVersion) == 0 {
return fmt.Errorf("value of --api-version must not have empty value")
}
if len(f.Kind) == 0 {
return fmt.Errorf("value of --kind must not have empty value")
}
kindFirstLetter := string(f.Kind[0])
if kindFirstLetter != strings.ToUpper(kindFirstLetter) {
return fmt.Errorf("value of --kind must start with an uppercase letter")
}
if strings.Count(f.APIVersion, "/") != 1 {
return fmt.Errorf("value of --api-version has wrong format (%v);"+
" format must be $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)", f.APIVersion)
}
if len(f.Kind) == 0 {
return fmt.Errorf("value of --kind must not have empty value")
}
kindFirstLetter := string(f.Kind[0])
if kindFirstLetter != strings.ToUpper(kindFirstLetter) {
return fmt.Errorf("value of --kind must start with an uppercase letter")
}
if strings.Count(f.APIVersion, "/") != 1 {
return fmt.Errorf("value of --api-version has wrong format (%v);"+
" format must be $GROUP_NAME/$VERSION (e.g app.example.com/v1alpha1)", f.APIVersion)
}
return nil
}
Loading