- 2. If this is a new env, create it
- - Add the k8s cloud to Juju
- - Bootstrap
- - Record it in the database
-
- 3. Connect to the Juju controller for this cloud
-
- """
- # cluster_uuid = reuse_cluster_uuid
- # if not cluster_uuid:
- # cluster_uuid = str(uuid4())
-
- ##################################################
- # TODO: Pull info from db based on the namespace #
- ##################################################
-
- if not reuse_cluster_uuid:
- # This is a new cluster, so bootstrap it
-
- cluster_uuid = str(uuid.uuid4())
-
- # Add k8s cloud to Juju (unless it's microk8s)
-
- # Does the kubeconfig contain microk8s?
- microk8s = self.is_microk8s_by_credentials(k8s_creds)
-
- # Name the new k8s cloud
- k8s_cloud = "{}-k8s".format(namespace)
-
- print("Adding k8s cloud {}".format(k8s_cloud))
- await self.add_k8s(k8s_cloud, k8s_creds)
-
- # Bootstrap Juju controller
- print("Bootstrapping...")
- await self.bootstrap(k8s_cloud, cluster_uuid, microk8s)
- print("Bootstrap done.")
-
- # Get the controller information
-
- # Parse ~/.local/share/juju/controllers.yaml
- # controllers.testing.api-endpoints|ca-cert|uuid
- print("Getting controller endpoints")
- with open(os.path.expanduser(
- "~/.local/share/juju/controllers.yaml"
- )) as f:
- controllers = yaml.load(f, Loader=yaml.Loader)
- controller = controllers['controllers'][cluster_uuid]
- endpoints = controller['api-endpoints']
- self.juju_endpoint = endpoints[0]
- self.juju_ca_cert = controller['ca-cert']
-
- # Parse ~/.local/share/juju/accounts
- # controllers.testing.user|password
- print("Getting accounts")
- with open(os.path.expanduser(
- "~/.local/share/juju/accounts.yaml"
- )) as f:
- controllers = yaml.load(f, Loader=yaml.Loader)
- controller = controllers['controllers'][cluster_uuid]
-
- self.juju_user = controller['user']
- self.juju_secret = controller['password']
-
- print("user: {}".format(self.juju_user))
- print("secret: {}".format(self.juju_secret))
- print("endpoint: {}".format(self.juju_endpoint))
- print("ca-cert: {}".format(self.juju_ca_cert))
-
- # raise Exception("EOL")
-
- self.juju_public_key = None
-
- config = {
- 'endpoint': self.juju_endpoint,
- 'username': self.juju_user,
- 'secret': self.juju_secret,
- 'cacert': self.juju_ca_cert,
- 'namespace': namespace,
- 'microk8s': microk8s,
- }