Skip to content

Conversation

hasbro17
Copy link
Contributor

@hasbro17 hasbro17 commented Apr 26, 2018

Added the operator-sdk generate alm-catalog cmd to generate catalog resources for ALM:
The build command will now generate the following catalog resources needed to create a new catalog entry in ALM.

  • Cluster Service Version: deploy/alm-catalog/csv.yaml
  • Package: deploy/alm-catalog/package.yaml
  • CRD: deploy/alm-catalog/crd.yaml

The generated CSV has minimal metadata since this is for demo purposes.
The RBAC rules in the CSV are more restricted to avoid giving admin access in a namespace but still covers enough resources to work out of the box for most operators.

The image and version of the CSV are required to be set by the flags:

operator-sdk generate alm-catalog --image=quay.io/example/memcached-operator:v0.0.1 --version=0.0.1

A few parameters such as the CSV version and package channel are fixed to default values for now since the operator-sdk build command doesn't provide enough information to set those.
Later on if the catalog generation is moved into its own command the catalog resources can be more configurable e.g:
operator-sdk generate catalog --image=<image> --version=<version> ...

/cc @fanminshi

@hasbro17
Copy link
Contributor Author

Current usage:

$ operator-sdk new memcached-operator --api-version=cache.example.com/v1alpha1 --kind=Memcached
...
$ operator-sdk build quay.io/example/memcached-operator:v0.0.1
$ ls deploy/alm-catalog/
crd.yaml      csv.yaml      package.yaml
$ cat deploy/alm-catalog/package.yaml
packageName: memcached
channels:
- name: alpha
  currentCSV: memcached.v0.0.1
$ cat deploy/alm-catalog/crd.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: memcacheds.cache.example.com
spec:
  group: cache.example.com
  names:
    kind: Memcached
    listKind: MemcachedList
    plural: memcacheds
    singular: memcached
  scope: Namespaced
  version: v1alpha1
$ cat deploy/alm-catalog/csv.yaml
apiVersion: app.coreos.com/v1alpha1
kind: ClusterServiceVersion-v1
metadata:
  name: memcached.v0.0.1
  namespace: placeholder
spec:
  install:
    strategy: deployment
    spec:
      permissions:
      - serviceAccountName: memcached-operator
        rules:
        - apiGroups:
          - cache.example.com
          resources:
          - "*"
          verbs:
          - "*"
        - apiGroups:
          - ""
          resources:
          - pods
          - services
          - endpoints
          - persistentvolumeclaims
          - events
          - configmaps
          - secrets
          verbs:
          - "*"
        - apiGroups:
          - apps
          resources:
          - deployments
          - daemonsets
          - replicasets
          - statefulsets
          verbs:
          - "*"
      deployments:
      - name: memcached-operator
        spec:
          replicas: 1
          selector:
            matchLabels:
              app: memcached-operator
          template:
            metadata:
              labels:
                app: memcached-operator
            spec:
              containers:
                - name: memcached-operator-alm-owned
                  image: quay.io/example/memcached-operator:v0.0.1
                  command:
                  - memcached-operator
                  imagePullPolicy: Always
                  env:
                  - name: MY_POD_NAMESPACE
                    valueFrom:
                      fieldRef:
                        fieldPath: metadata.namespace
                  - name: MY_POD_NAME
                    valueFrom:
                      fieldRef:
                        fieldPath: metadata.name
              restartPolicy: Always
              terminationGracePeriodSeconds: 5
              serviceAccountName: memcached-operator
              serviceAccount: memcached-operator
  customresourcedefinitions:
    owned:
      - description: Represents an instance of a Memcached application
        displayName: Memcached Application
        kind: Memcached
        name: memcacheds.cache.example.com
        version: v1alpha1
  version: 0.0.1
  labels:
    alm-owner-enterprise-app: memcached-operator
    alm-status-descriptors: memcached.v0.0.1

Testing out the current manifests by adding them as a new catalog entry for ALM.

@hasbro17
Copy link
Contributor Author

After some offline discussion I'm going to add a new command operator-sdk generate alm-catalog to generate the catalog manifests.
This way the catalog generation is optional.
Additionally the command would be passed the following flags to configure the manifests:

--image: The deployment image used in the CSV install plan
--version: CSV version

@hasbro17 hasbro17 changed the title [WIP] *: generate catalog resources on build *: add generate alm-catalog command Apr 26, 2018
@hasbro17
Copy link
Contributor Author

@fanminshi PTAL.
Added operator-sdk generate alm-catalog as a new cmd. The catalog templates are still the same.

$ operator-sdk generate alm-catalog --image=quay.io/example/memcached-operator:v0.0.1 --version=0.0.1
Generating ALM catalog manifests
$ ls deploy/alm-catalog
crd.yaml      csv.yaml      package.yaml

return err
}
path := filepath.Join(almDir, catalogPackageYaml)
if err := ioutil.WriteFile(path, buf.Bytes(), defaultExecFileMode); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

s/defaultExecFileMode/defaultFileMode/?

Those yaml files don't need exec permissions right?

return err
}
path = filepath.Join(almDir, catalogCRDYaml)
if err := ioutil.WriteFile(path, buf.Bytes(), defaultExecFileMode); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

s/defaultExecFileMode/defaultFileMode/

return err
}
path = filepath.Join(almDir, catalogCSVYaml)
return ioutil.WriteFile(path, buf.Bytes(), defaultExecFileMode)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/defaultExecFileMode/defaultFileMode/

return ioutil.WriteFile(operatorYaml, buf.Bytes(), defaultFileMode)
}

// RenderAlmCatalog generates catalog manifests "deploy/alm-catalog/*"
Copy link
Contributor

Choose a reason for hiding this comment

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

you might want to add a comment saying that the caller must ensure that the current pwd is at the project's root path.

@fanminshi
Copy link
Contributor

lgtm after nits

@hasbro17 hasbro17 merged commit 6ceeb4a into operator-framework:master Apr 26, 2018
@hasbro17 hasbro17 deleted the haseeb/generate-alm-manifests branch April 26, 2018 22:38
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