Skip to content

Commit

Permalink
Merge branch 'master' into issue-2372
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Jan 8, 2020
2 parents 1d95cbd + 872b051 commit 376395f
Show file tree
Hide file tree
Showing 36 changed files with 1,401 additions and 886 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
- Fail `operator-sdk olm-catalog gen-csv` if it is not run from a project's root, which the command already assumes is the case. ([#2322](https://github.com/operator-framework/operator-sdk/pull/2322))
- **Breaking Change:** Extract custom Ansible module `k8s_status`, which is now provided by the `operator_sdk.util` Ansible collection. See [developer_guide](https://github.com/operator-framework/operator-sdk/blob/master/doc/ansible/dev/developer_guide.md#custom-resource-status-management) for new usage. ([#2310](https://github.com/operator-framework/operator-sdk/pull/2310))
- Upgrade minimal Ansible version in the init projects from `2.6` to `2.9` for collections support. ([#2310](https://github.com/operator-framework/operator-sdk/pull/2310))
- Improve skip metrics logs when running the operator locally in order to make clear the information. ([#2190](https://github.com/operator-framework/operator-sdk/pull/2190))
- Upgrade [`controller-tools`](https://github.com/kubernetes-sigs/controller-tools) version from `v0.2.2` to [`v0.2.4`](https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.2.4). ([#2368](https://github.com/operator-framework/operator-sdk/pull/2368))

### Deprecated

- Deprecated `github.com/operator-framework/operator-sdk/pkg/restmapper` in favor of the `DynamicRESTMapper` implementation in [controller-runtime](https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/client/apiutil#NewDiscoveryRESTMapper). ([#2309](https://github.com/operator-framework/operator-sdk/pull/2309))

### Removed


### Bug Fixes
- Fix `operator-sdk build`'s `--image-build-args` to support spaces within quotes like `--label some.name="First Last"`. ([#2312](https://github.com/operator-framework/operator-sdk/pull/2312))
- Fix misleading Helm operator "release not found" errors during CR deletion. ([#2359](https://github.com/operator-framework/operator-sdk/pull/2359))
- Fix Ansible based image in order to re-trigger reconcile when playbooks are runner with error. ([#2375](https://github.com/operator-framework/operator-sdk/pull/2375))

## v0.13.0
Expand Down
1 change: 0 additions & 1 deletion cmd/operator-sdk/add/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func apiRun(cmd *cobra.Command, args []string) error {
&scaffold.Register{Resource: r},
&scaffold.Doc{Resource: r},
&scaffold.CR{Resource: r},
&scaffold.CRD{Resource: r, IsOperatorGo: projutil.IsOperatorGo()},
)
if err != nil {
return fmt.Errorf("api scaffold failed: (%v)", err)
Expand Down
17 changes: 11 additions & 6 deletions cmd/operator-sdk/add/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"path/filepath"
"strings"

gencrd "github.com/operator-framework/operator-sdk/internal/generate/crd"
gen "github.com/operator-framework/operator-sdk/internal/generate/gen"
"github.com/operator-framework/operator-sdk/internal/scaffold"
"github.com/operator-framework/operator-sdk/internal/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
Expand Down Expand Up @@ -74,7 +76,7 @@ func crdFunc(cmd *cobra.Command, args []string) error {
return err
}

log.Infof("Generating Custom Resource Definition (CRD) version %s for kind %s.", apiVersion, kind)
log.Infof("Generating CustomResourceDefinition (CRD) version %s for kind %s.", apiVersion, kind)

// generate CR/CRD file
resource, err := scaffold.NewResource(apiVersion, kind)
Expand All @@ -84,11 +86,6 @@ func crdFunc(cmd *cobra.Command, args []string) error {

s := scaffold.Scaffold{}
err = s.Execute(cfg,
&scaffold.CRD{
Input: input.Input{IfExistsAction: input.Skip},
Resource: resource,
IsOperatorGo: projutil.IsOperatorGo(),
},
&scaffold.CR{
Input: input.Input{IfExistsAction: input.Skip},
Resource: resource,
Expand All @@ -98,6 +95,14 @@ func crdFunc(cmd *cobra.Command, args []string) error {
return fmt.Errorf("crd scaffold failed: (%v)", err)
}

// This command does not consider an APIs dir. Instead it adds a plain CRD
// for the provided resource. We can use NewCRDNonGo to get this behavior.
gcfg := gen.Config{}
crd := gencrd.NewCRDNonGo(gcfg, *resource)
if err := crd.Generate(); err != nil {
return fmt.Errorf("error generating CRD for %s: %w", resource, err)
}

// update deploy/role.yaml for the given resource r.
if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil {
return fmt.Errorf("failed to update the RBAC manifest for the resource (%v, %v): (%v)", resource.APIVersion, resource.Kind, err)
Expand Down
9 changes: 8 additions & 1 deletion cmd/operator-sdk/generate/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"fmt"

"github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -45,5 +47,10 @@ func crdsFunc(cmd *cobra.Command, args []string) error {
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
}

return genutil.CRDGen()
// Skip usage printing on error, since this command will never fail from
// improper CLI usage.
if err := genutil.CRDGen(); err != nil {
log.Fatal(err)
}
return nil
}
53 changes: 7 additions & 46 deletions cmd/operator-sdk/internal/genutil/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ package genutil

import (
"fmt"
"path/filepath"
"strings"

gencrd "github.com/operator-framework/operator-sdk/internal/generate/crd"
gen "github.com/operator-framework/operator-sdk/internal/generate/gen"
"github.com/operator-framework/operator-sdk/internal/scaffold"
"github.com/operator-framework/operator-sdk/internal/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

log "github.com/sirupsen/logrus"
Expand All @@ -31,49 +29,12 @@ import (
func CRDGen() error {
projutil.MustInProjectRoot()

absProjectPath := projutil.MustGetwd()
repoPkg := projutil.GetGoPkg()
log.Info("Running CRD generator.")

gvMap, err := k8sutil.ParseGroupSubpackages(scaffold.ApisDir)
if err != nil {
return fmt.Errorf("failed to parse group versions: (%v)", err)
}
gvb := &strings.Builder{}
for g, vs := range gvMap {
gvb.WriteString(fmt.Sprintf("%s:%v, ", g, vs))
}

log.Infof("Running CRD generation for Custom Resource group versions: [%v]\n", gvb.String())

s := &scaffold.Scaffold{}
cfg := &input.Config{
Repo: repoPkg,
AbsProjectPath: absProjectPath,
ProjectName: filepath.Base(absProjectPath),
}
crds, err := k8sutil.GetCRDs(scaffold.CRDsDir)
if err != nil {
return err
}
for _, crd := range crds {
g, v, k := crd.Spec.Group, crd.Spec.Version, crd.Spec.Names.Kind
if v == "" {
if len(crd.Spec.Versions) != 0 {
v = crd.Spec.Versions[0].Name
} else {
return fmt.Errorf("crd of group %s kind %s has no version", g, k)
}
}
r, err := scaffold.NewResource(g+"/"+v, k)
if err != nil {
return err
}
err = s.Execute(cfg,
&scaffold.CRD{Resource: r, IsOperatorGo: projutil.IsOperatorGo()},
)
if err != nil {
return err
}
cfg := gen.Config{}
crd := gencrd.NewCRDGo(cfg)
if err := crd.Generate(); err != nil {
return fmt.Errorf("error generating CRDs from APIs in %s: %w", scaffold.ApisDir, err)
}

log.Info("CRD generation complete.")
Expand Down
26 changes: 24 additions & 2 deletions cmd/operator-sdk/new/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"path/filepath"
"strings"

gencrd "github.com/operator-framework/operator-sdk/internal/generate/crd"
gen "github.com/operator-framework/operator-sdk/internal/generate/gen"
"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"
Expand Down Expand Up @@ -231,7 +233,6 @@ func doAnsibleScaffold() error {
&scaffold.ServiceAccount{},
&scaffold.Role{},
&scaffold.RoleBinding{},
&scaffold.CRD{Resource: resource},
&scaffold.CR{Resource: resource},
&ansible.BuildDockerfile{GeneratePlaybook: generatePlaybook},
&ansible.RolesReadme{Resource: *resource},
Expand Down Expand Up @@ -267,6 +268,10 @@ func doAnsibleScaffold() error {
return fmt.Errorf("new ansible scaffold failed: (%v)", err)
}

if err = generateCRDNonGo(projectName, *resource); err != nil {
return err
}

// Remove placeholders from empty directories
err = os.Remove(filepath.Join(s.AbsProjectPath, roleFiles.Path))
if err != nil {
Expand Down Expand Up @@ -343,7 +348,6 @@ func doHelmScaffold() error {
&roleScaffold,
&scaffold.RoleBinding{IsClusterScoped: roleScaffold.IsClusterScoped},
&helm.Operator{},
&scaffold.CRD{Resource: resource},
&scaffold.CR{
Resource: resource,
Spec: crSpec,
Expand All @@ -353,12 +357,30 @@ func doHelmScaffold() error {
return fmt.Errorf("new helm scaffold failed: %w", err)
}

if err = generateCRDNonGo(projectName, *resource); err != nil {
return err
}

if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil {
return fmt.Errorf("failed to update the RBAC manifest for resource (%v, %v): %w", resource.APIVersion, resource.Kind, err)
}
return nil
}

func generateCRDNonGo(projectName string, resource scaffold.Resource) error {
crdsDir := filepath.Join(projectName, scaffold.CRDsDir)
gcfg := gen.Config{
Inputs: map[string]string{gencrd.CRDsDirKey: crdsDir},
OutputDir: crdsDir,
}
crd := gencrd.NewCRDNonGo(gcfg, resource)
if err := crd.Generate(); err != nil {
return fmt.Errorf("error generating CRD for %s: %w", resource, err)
}
log.Info("Generated CustomResourceDefinition manifests.")
return nil
}

func verifyFlags() error {
if operatorType != projutil.OperatorTypeGo && operatorType != projutil.OperatorTypeAnsible && operatorType != projutil.OperatorTypeHelm {
return errors.Wrap(projutil.ErrUnknownOperatorType{Type: operatorType}, "value of --type can only be `go`, `ansible`, or `helm`")
Expand Down
19 changes: 9 additions & 10 deletions code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## CoreOS Community Code of Conduct
## RedHat Community Code of Conduct

### Contributor Code of Conduct

Expand Down Expand Up @@ -33,29 +33,28 @@ This code of conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting a project maintainer, Brandon Philips
<brandon.philips@coreos.com>, and/or Rithu John <rithu.john@coreos.com>.
reported by contacting a project maintainer or the Operator SDK team <aos-operator-sdk@redhat.com>.

This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 1.2.0, available at
http://contributor-covenant.org/version/1/2/0/

### CoreOS Events Code of Conduct
### RedHat Events Code of Conduct

CoreOS events are working conferences intended for professional networking and
collaboration in the CoreOS community. Attendees are expected to behave
RedHat events are working conferences intended for professional networking and
collaboration in the RedHat community. Attendees are expected to behave
according to professional standards and in accordance with their employer’s
policies on appropriate workplace behavior.

While at CoreOS events or related social networking opportunities, attendees
While at RedHat events or related social networking opportunities, attendees
should not engage in discriminatory or offensive speech or actions including
but not limited to gender, sexuality, race, age, disability, or religion.
Speakers should be especially aware of these concerns.

CoreOS does not condone any statements by speakers contrary to these standards.
CoreOS reserves the right to deny entrance and/or eject from an event (without
RedHat does not condone any statements by speakers contrary to these standards.
RedHat reserves the right to deny entrance and/or eject from an event (without
refund) any individual found to be engaging in discriminatory or offensive
speech or actions.

Please bring any concerns to the immediate attention of designated on-site
staff, Brandon Philips <brandon.philips@coreos.com>, and/or Rithu John <rithu.john@coreos.com>.
staff, or the Operator SDK team <aos-operator-sdk@redhat.com>.
22 changes: 18 additions & 4 deletions doc/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type MemcachedSpec struct {
Size int32 `json:"size"`
}
type MemcachedStatus struct {
// Nodes are the names of the memcached pods
// Nodes are the names of the memcached pods
Nodes []string `json:"nodes"`
}
```
Expand All @@ -107,7 +107,22 @@ After modifying the `*_types.go` file always run the following command to update
$ operator-sdk generate k8s
```

### OpenAPI validation
### Updating CRD manifests

Now that `MemcachedSpec` and `MemcachedStatus` have fields and possibly annotations, the CRD corresponding to the API's group and kind must be updated. To do so, run the following command:

```console
$ operator-sdk generate crds
```

**Notes:**
- - Your CRD *must* specify exactly one [storage version][crd-storage-version]. Use the `+kubebuilder:storageversion` [marker][crd-markers] to indicate the GVK that should be used to store data by the API server. This marker should be in a comment above your `Memcached` type.

[crd-storage-version]:https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/#writing-reading-and-updating-versioned-customresourcedefinition-objects
[crd-markers]:https://book.kubebuilder.io/reference/markers/crd.html
[api-rules]: https://github.com/kubernetes/kubernetes/tree/36981002246682ed7dc4de54ccc2a96c1a0cbbdb/api/api-rules

#### OpenAPI validation

OpenAPIv3 schemas are added to CRD manifests in the `spec.validation` block when the manifests are generated. This validation block allows Kubernetes to validate the properties in a Memcached Custom Resource when it is created or updated.

Expand Down Expand Up @@ -146,7 +161,6 @@ To learn more about OpenAPI v3.0 validation schemas in Custom Resource Definitio
[generating-crd]: https://book.kubebuilder.io/reference/generating-crd.html
[markers]: https://book.kubebuilder.io/reference/markers.html
[crd-markers]: https://book.kubebuilder.io/reference/markers/crd-validation.html
[api-rules]: https://github.com/kubernetes/kubernetes/tree/36981002246682ed7dc4de54ccc2a96c1a0cbbdb/api/api-rules

## Add a new Controller

Expand Down Expand Up @@ -679,4 +693,4 @@ When the operator is not running in a cluster, the Manager will return an error
[result_go_doc]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/reconcile#Result
[metrics_doc]: ./user/metrics/README.md
[quay_link]: https://quay.io
[multi-namespaced-cache-builder]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder
[multi-namespaced-cache-builder]: https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder
13 changes: 7 additions & 6 deletions doc/user/migrating-existing-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,12 @@ This command will automatically update all CRD manifests.

#### CRD Versioning

<!-- TODO: change SDK version to the last release before controller-tools v0.2.0 refactor -->
Kubernetes 1.11+ supports CRD [`spec.versions`][crd-versions] and `spec.version` is [deprecated][crd-version-deprecated] as of Kubernetes 1.12. SDK versions `v0.10.x` and below leverage [`controller-tools@v0.1.x`][controller-tools]' CRD generator which generates a now-deprecated `spec.version` value based on the version contained in an API's import path. Names of CRD manifest files generated by those SDK versions contain the `spec.version`, i.e. one CRD manifest is created *per version in a group* with the file name format `<group>_<version>_<kind>_crd.yaml`. SDK versions `v0.11+` use `controller-tools@v0.2.x`, which generates `spec.versions` but not `spec.version` by default, and use the file name format `<full_group>_<resource>_crd.yaml`.

Kubernetes 1.11+ supports CRD [`spec.versions`][crd-versions] and `spec.version` is [deprecated][crd-version-deprecated] as of Kubernetes 1.12. SDK versions `v0.10.x` and below leverage [`controller-tools`][controller-tools]' CRD generator `v0.1.x` which generates a now-deprecated `spec.version` value based on the version contained in an APIs import path. Names of CRD manifest files generated by those SDK versions contain the `spec.version`, i.e. one CRD manifest is created *per version in a group* with the form `<group>_<version>_<kind>_crd.yaml`. The SDK is in the process of upgrading to `controller-tools` `v0.2.x`, which generates `spec.versions` but not `spec.version` by default. Once the upgrade is complete, future SDK versions will place all versions in a group in `spec.versions`. File names will then have the format `<full_group>_<resource>_crd.yaml`.

**Note**: `<full group>` is the full group name of your CRD while `<group>` is the last subdomain of `<full group>`, ex. `foo.bar.com` vs `foo`. `<resource>` is the plural lower-case of CRD `Kind` specified at `spec.names.plural`.

**Note:** If your operator does not have custom data manually added to its CRD's, you can skip to the [following section](#golang-api-migrations-types-and-commonalities); `operator-sdk generate crds` will handle CRD updates in that case.
**Notes:**
- `<full group>` is the full group name of your CRD while `<group>` is the last subdomain of `<full group>`, ex. `foo.bar.com` vs `foo`. `<resource>` is the plural lower-case of CRD `Kind` specified at `spec.names.plural`.
- Your CRD *must* specify exactly one [storage version][crd-storage-version]. Use the `+kubebuilder:storageversion` [marker][crd-markers] to indicate the GVK that should be used to store data by the API server. This marker should be in a comment above your `CatalogSourceConfig` type.
- If your operator does not have custom data manually added to its CRD's, you can skip to the [following section](#golang-api-migrations-types-and-commonalities); `operator-sdk generate crds` will handle CRD updates in that case.

Upgrading from `spec.version` to `spec.versions` will be demonstrated using the following CRD manifest example:

Expand Down Expand Up @@ -400,6 +399,8 @@ TODO
[k8s-versioning]:https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-versioning
[deepcopy-gen]:https://godoc.org/k8s.io/gengo/examples/deepcopy-gen
[client-gen]:https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/generating-clientset.md
[crd-storage-version]:https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/#writing-reading-and-updating-versioned-customresourcedefinition-objects
[crd-markers]:https://book.kubebuilder.io/reference/markers/crd.html
[controller-tools]:https://github.com/kubernetes-sigs/controller-tools
[crd-versions]:https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/
[crd-conv]:https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/#webhook-conversion
Expand Down
2 changes: 2 additions & 0 deletions doc/user/olm-catalog/csv-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

This document describes the semantics of Cluster Service Version (CSV) [code annotations][code-annotations-design] and lists all possible annotations.

**Note:** CSV annotations can only be used in Go Operator projects. Annotations for Ansible and Helm Operator projects will be added in the future.

## Usage

All annotations have a `+operator-sdk:gen-csv` prefix, denoting that they're parsed while executing [`operator-sdk olm-catalog gen-csv`][sdk-cli-ref].
Expand Down
2 changes: 2 additions & 0 deletions doc/user/olm-catalog/generating-a-csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This document describes how to manage the following lifecycle for your Operator
- **Upgrade your Operator** - Carry over any customizations you have made and ensure a rolling update to the next version of your Operator.
- **Refresh your CRDs** - If a new version has updated CRDs, refresh those definitions within the CSV automatically.

**Note:** `operator-sdk olm-catalog gen-csv` only officially supports Go Operators. Ansible and Helm Operators will be fully supported in the future. However, `gen-csv` _may_ work with Ansible and Helm Operators if their project structure aligns with that described below.

## Configuration

Operator SDK projects have an expected [project layout][doc-project-layout]. In particular, a few manifests are expected to be present in the `deploy` directory:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
k8s.io/kubectl v0.0.0
k8s.io/kubernetes v1.16.2 // indirect
sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/controller-tools v0.2.2
sigs.k8s.io/controller-tools v0.2.4
)

// Pinned to kubernetes-1.16.2
Expand Down
Loading

0 comments on commit 376395f

Please sign in to comment.