Requires Go version 1.14 - download for your development environment here.
This repository uses Go modules. You may need to export GO111MODULE=on
to turn modules support "on".
To setup host and member clusters - follow steps from https://github.com/codeready-toolchain/toolchain-e2e/blob/master/dev_install.adoc
Once the host and member operators are setup, we can add resources and watch the logs on the member-operator! To do so, open a new terminal and run the following commands
$ cd $GOPATH/src/github.com/codeready-toolchain/host-operator
# switch to appropriate namespace
$ oc apply -f '/path/to/masteruserrecord.yaml'
$ cd $GOPATH/github.com/codeready-toolchain/member-operator
# switch to appropriate namespace
$ oc apply -f '/path/to/useraccount.yaml'
Example masteruserrecord.yaml:
Note: The targetCluster
field must contain the correct member cluster name.
apiVersion: toolchain.dev.openshift.com/v1alpha1
kind: MasterUserRecord
metadata:
name: example
spec:
disabled: false
deprovisioned: false
userID: 86505192-a386-11e9-ad56-525400ad2b23
userAccounts:
- targetCluster: member-192-168-42-61-8443
syncIndex: 86505a
spec:
nsLimit: admin
userID: 86505192-a386-11e9-ad56-525400ad2b23
nsTemplateSet:
tierName: basic
namespaces:
- type: dev
revision: abcdef
- type: code
revision: abcdef
- type: stage
revision: abcdef
Example useraccount.yaml:
apiVersion: toolchain.dev.openshift.com/v1alpha1
kind: UserAccount
metadata:
name: example
spec:
userID: 86505192-a386-11e9-ad56-525400ad2b23
disabled: false
nsLimit: admin
nsTemplateSet:
tierName: basic
namespaces:
- type: dev
revision: abcdef
- type: code
revision: abcdef
- type: stage
revision: abcdef
Create a secret with Identity Provider credentials:
$ oc apply -f deploy/idp_secret.yaml
Create an Identity Provider:
$ oc apply -f deploy/idp.yaml
The CodeReady Toolchain architecture contains two types of clusters host
and member
.
To connect these two clusters together it is necessary to run a script scripts/add-cluster.sh that takes multiple flags like, --type
, --member-ns
, --host-ns
, --single-cluster
, --kube-config
. However you can see all these options by using ./scripts/add-cluster.sh -h
Assumption: This script assumes that you have host and member operators running on host and member clusters.
Scenario 1: Add Member to Host
./scripts/add-cluster.sh -t member
or
make add-member-to-host
Steps included:
-
goes to the cluster with
member
profile i.e. member cluster -
takes a secret of the SA (from the
member
) -
takes API endpoint and cluster name of the
member
cluster from Kube config -
goes to
host
profile -
takes cluster name of the
host
cluster from Kube config -
creates a secret with the SA token taken from the
member
-
creates
ToolchainCluster
CR representing the addedmember
Note: We have make target available for this i.e. make add-member-to-host
in member-operator, host-operator repository
Scenario 2: Add Host to Member
./scripts/add-cluster.sh -t host
or
make add-host-to-member
Steps included:
-
goes to the cluster with
host
profile i.e. host cluster -
takes a secret of the SA (from the
host
) -
takes API endpoint and cluster name of the
host
cluster from Kube config -
goes to
member
profile -
takes cluster name of the
member
cluster from Kube config -
creates a secret with the SA token taken from the
host
-
creates
ToolchainCluster
CR representing the addedhost
Note: We have make target available for this i.e. make add-host-to-member
member-operator, host-operator repository
Assumption: This script assumes that you have both host and member operators running on the same OpenShift cluster in respective namespace with all requires resources like Service Account, (Cluster)Role, (Cluster)RoleBinding, Custom Resource Definition. Scenario 1: Add Member to Host
./scripts/add-cluster.sh -t member -s
Steps included:
-
takes a secret of the SA (from the
toolchain-member-operator
namespace) -
takes API endpoint and cluster name of the
member
cluster from Kube config -
takes cluster name of the
host
cluster from Kube config -
creates a secret in
toolchain-host-operator
namespace with the SA token taken from thetoolchain-member-operator
ns -
creates
ToolchainCluster
intoolchain-host-operator
namespace CR representing the addedmember
Scenario 2: Add Host to Member
./scripts/add-cluster.sh -t host -s
Steps included:
-
takes a secret of the SA (from the
toolchain-host-operator
) -
takes API endpoint and cluster name of the
host
cluster from Kube config -
takes cluster name of the
member
cluster from Kube config -
creates a secret in
toolchain-member-operator
namespace with the SA token taken from thetoolchain-host-operator
ns -
creates
ToolchainCluster
intoolchain-member-operator
namespace CR representing the addedhost
Make sure you have two different clusters ready and available where the host-operator
should be running in the host cluster and member-operator
in the member cluster.
To do either you can pass kube-config using -kc
flag with kubeconfig having host-admin
and member-admin
contexts or if you don’t have kubeconfig you can provide required detail of cluster when promted for cluster URL and token.
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: REDACTED
server: https://api.host-1573997449.devcluster.openshift.com:6443
name: host-1573997449
- cluster:
certificate-authority-data: REDACTED
server: https://api.member-1573997449.devcluster.openshift.com:6443
name: member-1573997449
contexts:
- context:
cluster: host-1573997449
user: host-admin
name: host-admin
- context:
cluster: member-1573997449
user: member-admin
name: member-admin
current-context: host-admin
kind: Config
preferences: {}
users:
- name: host-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
- name: member-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
export KUBECONFIG=kubeconfig
./scripts/add-cluster.sh -t host -s -t member -mn ${MEMBER_OPERATOR_NS} -hn ${HOST_OPERATOR_NS} -kc ${KUBECONFIG}
./scripts/add-cluster.sh -t member -s -t member -mn ${MEMBER_OPERATOR_NS} -hn ${HOST_OPERATOR_NS} -kc ${KUBECONFIG}
If you are running member-operator
and host-operator
in different namespaces other than default (i.e. not in toolchain-member-operator
or toolchain-host-operator
), you can do it passing -mn or -hs
flags
./scripts/add-cluster.sh --type host --member-ns member-operator-0xdf4 --host-ns host-operator-hj6d7 --single-cluster
While overwriting default namespaces, please do remember to provide member and host namespace. If you are trying to overwrite with single namespace, it’s not supported at this point.