Playground-injector
The playground-injector trait injects the playground CLI in the component. This trait allows to manage the Napptive account inside the component. Once the trait is added the CLI is ready to be used.
The following snippet shows an example application with a component and a playground-injector trait.
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: my-app
annotations:
version: "v1.0.0"
description: "My Application"
spec:
components:
- name: busybox
type: worker
properties:
image: my-app-image:v1.0.0
cpu: "0.1"
memory: 128Mi
traits:
- type: playground-injector
properties:
pat: <Personal Access Token> # (Optional) Napptive Personal Access Token https://docs.napptive.com/playground/Web.html#pats-personal-access-token
version: <CLI version> # (Optional) Playground CLI version (v4.4.0 for example). By default, the latest version will be installed
How to log in to the platform
To log into your Napptive account from within the component, there are two methods available: using a personal access token, or a headless login:
-
Using a Personal Access Token or
In this case, we recommend to set the
pat
property in the trait, or set thePLAYGROUND_PAT
environment variable before login. Alternatively, you can mount a volume with a pat file and use it to log with the CLI. Once the PAT is set, use:playground login --pat
For more information, check the existing tutorial on how to create and manage Personal Access Tokens.
-
Using headless login functionality
With this approach, the CLI will generate a URL that needs to be pasted into a browser, and the browser will return a token that will be copied into the terminal. To launch this type of login process use:
playground login --headless
Using a secret to store the PAT
In some cases, you may be interested in storing the PAT in a secret; the example below shows an application that creates a secret to store the pat and mounts that information in the PLAYGROUND_PAT
environment variable.
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: my-app
annotations:
version: "v1.0.0"
description: "My Application"
spec:
components:
- name: busybox
type: worker
properties:
image: my-app-image:v1.0.0
cpu: "0.1"
memory: 128Mi
traits:
- type: playground-injector
properties:
version: <CLI version> # (Optional) Playground CLI version (v4.4.0 for example). If version not filled, the latest version will be installed
- type: storage # Storage trait to generate a Secret with your PAT
properties:
secret:
- name: pat-secret
mountPath: mount/pat-secret # (optional) if the login command uses --patFile option
mountToEnv: # (optional) mount to Environment variables if the login command uses PLAYGROUND_PAT option
envName: PLAYGROUND_PAT # environment variable
secretKey: pat # secret key
data:
pat: <base64 pat>