Skip to content

*: generate k8s manifest#72

Merged
fanminshi merged 3 commits intooperator-framework:masterfrom
fanminshi:gen_manifest
Mar 1, 2018
Merged

*: generate k8s manifest#72
fanminshi merged 3 commits intooperator-framework:masterfrom
fanminshi:gen_manifest

Conversation

@fanminshi
Copy link
Copy Markdown
Contributor

@fanminshi fanminshi commented Mar 1, 2018

this pr allows operator-sdk build to create deploy/operator.yaml base on metadata in config/config.yaml and the input image.

@fanminshi
Copy link
Copy Markdown
Contributor Author

Manual Test:

$ operator-sdk new app-operator --api-version=app.example.com/v1alpha1 --kind=AppService
$ cd app-operator
$ operator-sdk build quay.io/coreos/operator-sdk-dev:app-operator
...
$ app-operator fanminshi$ cat deploy/operator.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: app.example.com/v1alpha1s.app.example.com
spec:
  group: app.example.com
  names:
    kind: app.example.com/v1alpha1
    listKind: app.example.com/v1alpha1List
    plural: app.example.com/v1alpha1s
    singular: app.example.com/v1alpha1
  scope: Namespaced
  version: v1alpha1
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: app-operator
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: app-operator
    spec:
      containers:
        - name: app-operator
          image: quay.io/coreos/operator-sdk-dev:app-operator
          command:
          - app-operator

@fanminshi
Copy link
Copy Markdown
Contributor Author

cc/ @hasbro17

@fanminshi fanminshi mentioned this pull request Mar 1, 2018
21 tasks
@hasbro17
Copy link
Copy Markdown
Contributor

hasbro17 commented Mar 1, 2018

The CRD output above seems incorrect.

For --api-version=app.example.com/v1alpha1 and --kind=AppService the plural name is appservices and the CRD should look like:

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  # name is of the form <plural>.<group>
  name: appservices.app.example.com
spec:
  group: app.example.com
  names:
    # kind is normally the CamelCased singular type
    kind: AppService
    listKind: AppServiceList
    plural: appservices
    singular: appservice
  scope: Namespaced
  version: v1alpha1

@fanminshi
Copy link
Copy Markdown
Contributor Author

@hasbro17 good catch.

@fanminshi
Copy link
Copy Markdown
Contributor Author

latest output:

$ cat deploy/operator.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: appservices.app.example.com
spec:
  group: app.example.com
  names:
    kind: AppService
    listKind: AppServiceList
    plural: appservices
    singular: appservice
  scope: Namespaced
  version: v1alpha1
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: app-operator
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: app-operator
    spec:
      containers:
        - name: app-operator
          image: quay.io/coreos/operator-sdk-dev:app-operator
          command:
          - app-operator

@fanminshi
Copy link
Copy Markdown
Contributor Author

all fixed PTAL cc/ @hasbro17

"os"
"os/exec"

"github.com/coreos/operator-sdk/pkg/generator"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leave a line here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@fanminshi
Copy link
Copy Markdown
Contributor Author

All Fixed. CC/ @hasbro17

Comment thread pkg/generator/gen_deploy.go Outdated
t := template.New("deploy/operator.yaml")
t, err := t.Parse(operatorYamlTmpl)
if err != nil {
return err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably best to wrap the error

return fmt.Errorf("failed to parse operator yaml template: %v", err)

Comment thread pkg/generator/gen_deploy.go Outdated

// renderOperatorYaml generates deploy/operator.yaml.
func renderOperatorYaml(w io.Writer, kind, apiVersion, projectName, image string) error {
t := template.New("deploy/operator.yaml")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make the file name deploy/operator.yaml a constant.

@hasbro17
Copy link
Copy Markdown
Contributor

hasbro17 commented Mar 1, 2018

LGTM after nits

@fanminshi
Copy link
Copy Markdown
Contributor Author

fixed! merging!

@fanminshi fanminshi merged commit 7e5438e into operator-framework:master Mar 1, 2018
m1kola pushed a commit to m1kola/operator-sdk that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants