Переглянути джерело

manifest: use OpenShift templates

Use an OpenShift template to deploy the plugin. This avoids needing to
manually replace the plugin name, namespace, and image in the previous
manifest.yaml file.
Samuel Padgett 4 роки тому
батько
коміт
3d0c7471e2
3 змінених файлів з 173 додано та 138 видалено
  1. 28 21
      README.md
  2. 0 117
      manifest.yaml
  3. 145 0
      template.yaml

+ 28 - 21
README.md

@@ -9,9 +9,7 @@ to build and run the example.
 ## Update the plugin metadata
 
 After cloning this repo, you should update the plugin metadata such as the
-plugin name. The metadata is defined in the `consolePlugin` stanza of
-package.json. Additionally, update references to `console-plugin-template` and
-the plugin image in manifest.yaml. Your plugin must have a unique name.
+plugin name in the `consolePlugin` declaration of package.json.
 
 ## Local development
 
@@ -27,37 +25,46 @@ for details on how to run OpenShift console using local plugins.
 When a local console server is running, visit <http://localhost:9000/example>
 to see the example plugin page.
 
+## Docker image
+
+1. Build the image:
+   ```sh
+   docker build -t quay.io/my-repositroy/my-plugin:latest .
+   ```
+2. Run the image:
+   ```sh
+   docker run -it --rm -d -p 9001:80 quay.io/my-repository/my-plugin:latest
+   ```
+3. Push the image to the image registry:
+   ```sh
+   docker push quay.io/my-repository/my-plugin:latest
+   ```
+
 ## Deployment on cluster
 
-You can deploy the plugin to a cluster by applying `manifest.yaml`.
+After pushing an image with your changes to an image registry, you can deploy
+the plugin to a cluster by instantiating the template:
 
 ```sh
-oc apply -f manifest.yaml
+oc process -f template.yaml \
+  -p PLUGIN_NAME=my-plugin \
+  -p NAMESPACE=my-plugin-namespace \
+  -p IMAGE=quay.io/my-repository/my-plugin:latest \
+  | oc create -f -
 ```
 
+The `PLUGIN_NAME` value must match the plugin name you used in the
+`consolePlugin` declaration of package.json.
+
 Once deployed, patch the
 [Console operator](https://github.com/openshift/console-operator)
 config to enable the plugin.
 
 ```sh
-oc patch consoles.operator.openshift.io cluster --patch '{ "spec": { "plugins": ["$PLUGIN_NAME"] } }' --type=merge
+oc patch consoles.operator.openshift.io cluster \
+  --patch '{ "spec": { "plugins": ["my-plugin"] } }' --type=merge
 ```
 
-## Docker image
-
-1. Build the image:
-   ```sh
-   docker build -t quay.io/$USER/$PLUGIN_NAME:latest .
-   ```
-2. Run the image:
-   ```sh
-   docker run -it --rm -d -p 9001:80 quay.io/$USER/$PLUGIN_NAME:latest
-   ```
-3. Push the image to image registry:
-   ```sh
-   docker push quay.io/$USER/$PLUGIN_NAME:latest
-   ```
-
 ## References
 
 * [Console Plugin SDK README](https://github.com/openshift/console/tree/master/frontend/packages/console-dynamic-plugin-sdk)

+ 0 - 117
manifest.yaml

@@ -1,117 +0,0 @@
-apiVersion: v1
-kind: Namespace
-metadata:
-  name: console-plugin-template
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: console-plugin-template
-  namespace: console-plugin-template
-  labels:
-    app: console-plugin-template
-    app.kubernetes.io/component: console-plugin-template
-    app.kubernetes.io/instance: console-plugin-template
-    app.kubernetes.io/part-of: console-plugin-template
-    app.openshift.io/runtime-namespace: console-plugin-template
-spec:
-  replicas: 1
-  selector:
-    matchLabels:
-      app: console-plugin-template
-  template:
-    metadata:
-      labels:
-        app: console-plugin-template
-    spec:
-      containers:
-        - name: console-plugin-template
-          image: quay.io/spadgett/console-plugin-template:latest
-          ports:
-            - containerPort: 9443
-              protocol: TCP
-          imagePullPolicy: Always
-          volumeMounts:
-            - name: plugin-serving-cert
-              readOnly: true
-              mountPath: /var/serving-cert
-            - name: nginx-conf
-              readOnly: true
-              mountPath: /etc/nginx/nginx.conf
-              subPath: nginx.conf
-      volumes:
-        - name: plugin-serving-cert
-          secret:
-            secretName: plugin-serving-cert
-            defaultMode: 420
-        - name: nginx-conf
-          configMap:
-            name: nginx-conf
-            defaultMode: 420
-      restartPolicy: Always
-      dnsPolicy: ClusterFirst
-  strategy:
-    type: RollingUpdate
-    rollingUpdate:
-      maxUnavailable: 25%
-      maxSurge: 25%
----
-apiVersion: v1
-kind: ConfigMap
-metadata:
-  name: nginx-conf
-  namespace: console-plugin-template
-  labels:
-    app: console-plugin-template
-    app.kubernetes.io/part-of: console-plugin-template
-data:
-  nginx.conf: |
-    error_log /dev/stdout info;
-    events {}
-    http {
-      access_log         /dev/stdout;
-      include            /etc/nginx/mime.types;
-      default_type       application/octet-stream;
-      keepalive_timeout  65;
-      server {
-        listen              9443 ssl;
-        ssl_certificate     /var/serving-cert/tls.crt;
-        ssl_certificate_key /var/serving-cert/tls.key;
-        root                /usr/share/nginx/html;
-      }
-    }
----
-apiVersion: v1
-kind: Service
-metadata:
-  annotations:
-    service.alpha.openshift.io/serving-cert-secret-name: plugin-serving-cert
-  name: console-plugin-template
-  namespace: console-plugin-template
-  labels:
-    app: console-plugin-template
-    app.kubernetes.io/component: console-plugin-template
-    app.kubernetes.io/instance: console-plugin-template
-    app.kubernetes.io/part-of: console-plugin-template
-spec:
-  ports:
-    - name: 9443-tcp
-      protocol: TCP
-      port: 9443
-      targetPort: 9443
-  selector:
-    app: console-plugin-template
-  type: ClusterIP
-  sessionAffinity: None
----
-apiVersion: console.openshift.io/v1alpha1
-kind: ConsolePlugin
-metadata:
-  name: console-plugin-template
-spec:
-  displayName: 'Console Plugin Template'
-  service:
-    name: console-plugin-template
-    namespace: console-plugin-template
-    port: 9443
-    basePath: '/'

+ 145 - 0
template.yaml

@@ -0,0 +1,145 @@
+apiVersion: template.openshift.io/v1
+kind: Template
+metadata:
+  name: console-plugin-template
+  annotations:
+    openshift.io/display-name: OpenShift Console Plugin Template
+    openshift.io/documentation-url: "https://github.com/spadgett/console-plugin-template"
+    description: >-
+      nginx HTTP server for an OpenShift console plugin creating using the
+      template at https://github.com/spadgett/console-plugin-template
+    iconClass: icon-nginx
+    tags: openshift,console,plugin,nginx
+parameters:
+- description: Name of your plugin. This name must match the name in the consolePlugin declaration in package.json.
+  name: PLUGIN_NAME
+  value: console-plugin-template
+  required: true
+- description: Namespace for your plugin. The namespace will be created by the template.
+  name: NAMESPACE
+  value: console-plugin-template
+  required: true
+- description: Container image of the plugin.
+  name: IMAGE
+  value: quay.io/spadgett/console-plugin-template:latest
+  required: true
+message: >-
+  To enable the plugin on the cluster, run the following command:
+
+  oc patch consoles.operator.openshift.io cluster --patch '{ "spec": { "plugins": ["${PLUGIN_NAME}"] } }' --type=merge
+
+  For more information about using this template, see https://github.com/spadgett/console-plugin-template
+objects:
+  - apiVersion: v1
+    kind: Namespace
+    metadata:
+      name: '${NAMESPACE}'
+  - apiVersion: apps/v1
+    kind: Deployment
+    metadata:
+      name: '${PLUGIN_NAME}'
+      namespace: '${NAMESPACE}'
+      labels:
+        app: '${PLUGIN_NAME}'
+        app.kubernetes.io/component: '${PLUGIN_NAME}'
+        app.kubernetes.io/instance: '${PLUGIN_NAME}'
+        app.kubernetes.io/part-of: '${PLUGIN_NAME}'
+        app.openshift.io/runtime-namespace: '${NAMESPACE}'
+    spec:
+      replicas: 1
+      selector:
+        matchLabels:
+          app: '${PLUGIN_NAME}'
+      template:
+        metadata:
+          labels:
+            app: '${PLUGIN_NAME}'
+        spec:
+          containers:
+            - name: '${PLUGIN_NAME}'
+              image: '${IMAGE}'
+              ports:
+                - containerPort: 9443
+                  protocol: TCP
+              imagePullPolicy: Always
+              volumeMounts:
+                - name: plugin-serving-cert
+                  readOnly: true
+                  mountPath: /var/serving-cert
+                - name: nginx-conf
+                  readOnly: true
+                  mountPath: /etc/nginx/nginx.conf
+                  subPath: nginx.conf
+          volumes:
+            - name: plugin-serving-cert
+              secret:
+                secretName: plugin-serving-cert
+                defaultMode: 420
+            - name: nginx-conf
+              configMap:
+                name: nginx-conf
+                defaultMode: 420
+          restartPolicy: Always
+          dnsPolicy: ClusterFirst
+      strategy:
+        type: RollingUpdate
+        rollingUpdate:
+          maxUnavailable: 25%
+          maxSurge: 25%
+  - apiVersion: v1
+    kind: ConfigMap
+    metadata:
+      name: nginx-conf
+      namespace: '${NAMESPACE}'
+      labels:
+        app: '${PLUGIN_NAME}'
+        app.kubernetes.io/part-of: '${PLUGIN_NAME}'
+    data:
+      nginx.conf: |
+        error_log /dev/stdout info;
+        events {}
+        http {
+          access_log         /dev/stdout;
+          include            /etc/nginx/mime.types;
+          default_type       application/octet-stream;
+          keepalive_timeout  65;
+          server {
+            listen              9443 ssl;
+            ssl_certificate     /var/serving-cert/tls.crt;
+            ssl_certificate_key /var/serving-cert/tls.key;
+            root                /usr/share/nginx/html;
+          }
+        }
+  - apiVersion: v1
+    kind: Service
+    metadata:
+      annotations:
+        service.alpha.openshift.io/serving-cert-secret-name: plugin-serving-cert
+      name: '${PLUGIN_NAME}'
+      namespace: '${NAMESPACE}'
+      labels:
+        app: '${PLUGIN_NAME}'
+        app.kubernetes.io/component: '${PLUGIN_NAME}'
+        app.kubernetes.io/instance: '${PLUGIN_NAME}'
+        app.kubernetes.io/part-of: '${PLUGIN_NAME}'
+    spec:
+      ports:
+        - name: 9443-tcp
+          protocol: TCP
+          port: 9443
+          targetPort: 9443
+      selector:
+        app: '${PLUGIN_NAME}'
+      type: ClusterIP
+      sessionAffinity: None
+  - apiVersion: console.openshift.io/v1alpha1
+    kind: ConsolePlugin
+    metadata:
+      name: '${PLUGIN_NAME}'
+    spec:
+      displayName: 'Console Plugin Template'
+      service:
+        name: '${PLUGIN_NAME}'
+        namespace: '${NAMESPACE}'
+        port: 9443
+        basePath: '/'