Skip to content

Commit

Permalink
Add clusterdomain CRD & controller
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com>
  • Loading branch information
yeahdongcn committed Nov 27, 2023
1 parent f27b71b commit 213659a
Show file tree
Hide file tree
Showing 24 changed files with 1,705 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -100,7 +100,7 @@ help: ## Display this help.
manifests: SED_SEARCH_STRING := scope: Namespaced
manifests: SED_REPLACE_STRING := scope: Cluster
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./vendor/github.com/loft-sh/api/v3/pkg/apis/storage/v1/;./controllers/..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./vendor/github.com/loft-sh/api/v3/pkg/apis/storage/v1/;./api/v1/;./controllers/..." output:crd:artifacts:config=config/crd/bases
grep -l -RE "$(SED_SEARCH_STRING)" config/crd/bases \
| xargs $(SED) -i -E 's#$(SED_SEARCH_STRING)$$#$(SED_REPLACE_STRING)#g'

Expand Down
8 changes: 8 additions & 0 deletions PROJECT
Expand Up @@ -21,4 +21,12 @@ resources:
group: storage
kind: VirtualClusterTemplate
version: v1
- api:
crdVersion: v1
controller: true
domain: openloft.cn
group: storage
kind: ClusterDomain
path: github.com/openloft/openloft/api/v1
version: v1
version: "3"
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -31,7 +31,13 @@
kubectl apply -f https://raw.githubusercontent.com/openloft/openloft/main/deploy/manifests.yaml
```

### 3. Create a vCluster Template
### 3. Create a Cluster Domain

```bash
kubectl apply -f https://raw.githubusercontent.com/openloft/openloft/main/config/samples/storage_v1_clusterdomain.yaml
```

### 4. Create a vCluster Template

There are two types of vCluster templates in sample, `isolated` and `default`. The `isolated` template will create a vCluster with a [resource quota](https://kubernetes.io/docs/concepts/policy/resource-quotas/). The `default` template will create a vCluster with no resource quota.

Expand All @@ -41,20 +47,20 @@ The below command will create a `isolated` vCluster template.
kubectl apply -f https://raw.githubusercontent.com/openloft/openloft/main/config/samples/isolated/storage_v1_virtualclustertemplate.yaml
```

### 4. Create a vCluster Instance
### 5. Create a vCluster Instance

```bash
kubectl apply -f https://raw.githubusercontent.com/openloft/openloft/main/config/samples/isolated/storage_v1_virtualclusterinstance.yaml
```

By running the above command, a vCluster called `isolated-sample-openloft-cn` would be created in the namespace `vc-isolated-sample-openloft-cn`. And an ingress would be created with the name `ingress-isolated-sample-openloft-cn`.
By running the above command, a vCluster called `isolated-sample` would be created in the namespace `vc-isolated-sample`.

### 5. Retrieving the kube config from the vCluster secret
### 6. Retrieving the kube config from the vCluster secret

The secret is prefixed with `vc-` and ends with the vCluster name, so a vCluster instance called `isolated-sample.openloft.cn` would create a secret called `vc-isolated-sample-openloft-cn` in the namespace `vc-isolated-sample-openloft-cn`. You can retrieve the kube config after the vCluster has started via:
The secret is prefixed with `vc-` and ends with the vCluster name, so a vCluster instance called `isolated-sample` would create a secret called `vc-isolated-sample` in the namespace `vc-isolated-sample`. You can retrieve the kube config after the vCluster has started via:

```
kubectl get secret vc-isolated-sample-openloft-cn -n vc-isolated-sample-openloft-cn --template={{.data.config}} | base64 -D > kubeconfig.yaml
kubectl get secret vc-isolated-sample -n vc-isolated-sample --template={{.data.config}} | base64 -D > kubeconfig.yaml
```

The secret will hold a kube config in this format:
Expand Down Expand Up @@ -89,7 +95,7 @@ e.g. `/etc/hosts` on macOS/Linux:
127.0.0.1 isolated-sample.openloft.cn
```

### 6. Accessing the vCluster
### 7. Accessing the vCluster

You can access the vCluster via:

Expand Down
56 changes: 56 additions & 0 deletions api/v1/clusterdomain_types.go
@@ -0,0 +1,56 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ClusterDomainSpec defines the desired state of ClusterDomain
type ClusterDomainSpec struct {
Domain string `json:"domain,omitempty"`
}

// ClusterDomainStatus defines the observed state of ClusterDomain
type ClusterDomainStatus struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster

// ClusterDomain is the Schema for the clusterdomains API
type ClusterDomain struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ClusterDomainSpec `json:"spec,omitempty"`
Status ClusterDomainStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ClusterDomainList contains a list of ClusterDomain
type ClusterDomainList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterDomain `json:"items"`
}

func init() {
SchemeBuilder.Register(&ClusterDomain{}, &ClusterDomainList{})
}
89 changes: 89 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions config/crd/bases/storage.openloft.cn_clusterdomains.yaml
@@ -0,0 +1,48 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
name: clusterdomains.storage.openloft.cn
spec:
group: storage.openloft.cn
names:
kind: ClusterDomain
listKind: ClusterDomainList
plural: clusterdomains
singular: clusterdomain
scope: Cluster
versions:
- name: v1
schema:
openAPIV3Schema:
description: ClusterDomain is the Schema for the clusterdomains API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ClusterDomainSpec defines the desired state of ClusterDomain
properties:
domain:
type: string
type: object
status:
description: ClusterDomainStatus defines the observed state of ClusterDomain
type: object
type: object
served: true
storage: true
subresources:
status: {}

0 comments on commit 213659a

Please sign in to comment.