Please follow the following instructions to install SPI and use with application-service.
Note: SPI cannot be used on a Red Hat OpenShift Local (formerly, CRC) cluster.
In order to use HAS resources (e.g. Application, Component, ComponentDetectionQuery) with private git repositories, SPI must be installed on the same cluster as HAS (TODO review HAS install instructions):
-
Clone the SPI operator repo and run the make command corresponding to your target cluster type e.g.
make deploy_openshift -
Set up SPI
- Get SPI oauth route URL from
spi-systemnamespaceoc get routes -n spi-system - Create oauth app in GitHub (
Settings->Developer Settings->OAuth Apps)- Use the SPI oauth url as the Application Callback URL.
- Homepage URL does not matter
- Record the Client ID and Client Secret values
- To set up a Github Oauth app with SPI, modify the overlay in your cloned SPI repo that corresponds with the cluster type e.g. in config/overlays/openshift_vault/config.yaml, replace the
clientIdandclientSecretwith the values from the oauth app you created in step 2. Runkustomize build config/overlays/openshift_vault | kubectl apply -f -to update theshared-configuration-filesecret
- Get SPI oauth route URL from
-
In Github, generate a new classic token with User and Repo scope and note down the token value.
-
To create a token secret to use with HAS, draft a
SPIAccessTokenBindingresource with the following contents:apiVersion: appstudio.redhat.com/v1beta1 kind: SPIAccessTokenBinding metadata: name: test-access-token-binding spec: permissions: required: - type: rw area: repository repoUrl: https://github.com/johnmcollier/private-devfile-repo secret: name: token-secret type: kubernetes.io/basic-auth
-
Create the resource in the namespace you will be creating HAS resources in. Upon successful creation, the CR will be in
AwaitingTokenDataphase status and a correspondingSPIAccessTokenCR will be created in the same namespace. -
Upload the token:
-
Set the TARGET_NAMESPACE to where your CRs instances are. Run
UPLOAD_URL=$(kubectl get spiaccesstokenbinding/test-access-token-binding -n $TARGET_NAMESPACE -o json | jq -r .status.uploadUrl) -
Inject the token with the curl command, where TOKEN is the console admin token and GITHUB_TOKEN is the token created in main step 1 above
curl -v -H 'Content-Type: application/json' -H "Authorization: bearer "$TOKEN -d "{ \"access_token\": \"$GITHUB_TOKEN\" }" $UPLOAD_URL -
The state of the
SPIAccessTokenBindingCR should change toInjectedand the state of theSPIAccessTokenshould beReady -
This will also create a K8s secret corresponding to the name of the secret that was specified in the
SPIAccessTokenBindingcreated in main step 2 above, for exampletoken-secret. Use the secret in HAS CRs for private repositories.
-
Now, with the token secret created for the git repository, when creating HAS resources (Components, ComponentDetectionQueries) that need to access that private Git repository, just pass in the token secret to the resource:
Component
apiVersion: appstudio.redhat.com/v1alpha1
kind: Component
metadata:
name: component-sample
spec:
componentName: backend
application: application-sample
replicas: 1
source:
git:
url: https://github.com/devfile-resources/devfile-private.git
secret: token-secretComponentDetectionQuery
apiVersion: appstudio.redhat.com/v1alpha1
kind: ComponentDetectionQuery
metadata:
name: componentdetectionquery-sample
spec:
git:
url: https://github.com/devfile-resources/multi-component-private.git
secret: token-secret