Skip to content

Commit

Permalink
Added longhorn via fleet
Browse files Browse the repository at this point in the history
  • Loading branch information
e-minguez committed Jun 22, 2023
1 parent 8ecca3f commit 780a0a6
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 2 deletions.
73 changes: 73 additions & 0 deletions fleet-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,77 @@ kubectl apply -f https://raw.githubusercontent.com/suse-edge/misc/main/fleet-exa

```
kubectl apply -f https://raw.githubusercontent.com/suse-edge/misc/main/fleet-examples/gitrepos/elemental-gitrepo.yaml
```

* [Longhorn](./fleets/longhorn) - [Longhorn](https://longhorn.io/):

```
kubectl apply -f https://raw.githubusercontent.com/suse-edge/misc/main/fleet-examples/gitrepos/longhorn-gitrepo.yaml
```

A few notes about this example:

* The Longhorn UI is not exposed by default. If you want to expose it, you need to specify a couple of Helm values such as:

```
ingress:
enabled: true
host: "longhorn-example.com"
```

You can modify the Longhorn's [fleet.yaml](./fleets/longhorn/fleet.yaml) file to fit your needs.

* The fleet file is also set to read Helm custom values in a configmap created in the `fleet-local` namespace:

```
valuesFrom:
- configMapKeyRef:
name: longhorn-chart-values
# default to namespace of bundle
namespace: fleet-local
key: values.yaml
```

Basically you can create a configmap there with the `values.yaml` content you want to provide. This is not restricted to ingress but anything included in the [Longhorn Helm Chart values.yaml](https://github.com/longhorn/longhorn/blob/master/chart/values.yaml) can be used:

```
cat <<- EOF | kubectl apply -f -
apiVersion: v1
data:
values.yaml: |
ingress:
enabled: true
host: "longhorn-example.com"
kind: ConfigMap
metadata:
name: longhorn-chart-values
namespace: fleet-local
EOF
```

* There is a [create-cm.yaml](./fleets/longhorn/create-cm.yaml) file that creates that configmap with the ingress settings to be exposed in a particular conditions:
* If the traefik Ingress controller is deployed
* If it is using sslip.io
This means that if you are using the [create-vm.sh](../slemicro/create_vm.sh) script, you should be able to leverage it as:

```
create_vm.sh -f myvm
export KUBECONFIG=$(get_kubeconfig.sh -f myvm -w)
kubectl apply -f fleets/longhorn/create-cm.yaml
kubectl apply -f https://raw.githubusercontent.com/suse-edge/misc/main/fleet-examples/gitrepos/longhorn-gitrepo.yaml
```

* For the `local` cluster, there is also a Kustomize overlay to enable basic authentication for the Longhorn UI. See the [fleets/longhorn/overlays/local/](./fleets/longhorn/overlays/local/) for more information.

**NOTE:** Due to https://github.com/rancher/fleet/issues/1507, this needs to be done before applying the longhorn gitrepo:

```
helm -n cattle-fleet-system upgrade --create-namespace fleet-crd https://github.com/rancher/fleet/releases/download/v0.7.0/fleet-crd-0.7.0.tgz
helm -n cattle-fleet-system upgrade --create-namespace fleet https://github.com/rancher/fleet/releases/download/v0.7.0/fleet-0.7.0.tgz
```

* To uninstall the application, it is required to set the `deleting-confirmation-flag` to true as per [the instructions](https://longhorn.io/docs/1.4.2/deploy/uninstall/#prerequisite) before removing the Helm chart or the `gitrepo` object:

```
kubectl -n longhorn-system patch -p '{"value": "true"}' --type=merge lhs deleting-confirmation-flag
```
5 changes: 5 additions & 0 deletions fleet-examples/fleets/longhorn/longhorn-crd/fleet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defaultNamespace: longhorn-system
helm:
releaseName: longhorn-crd
chart: longhorn-crd
repo: https://charts.rancher.io/
27 changes: 27 additions & 0 deletions fleet-examples/fleets/longhorn/longhorn/fleet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defaultNamespace: longhorn-system
helm:
releaseName: longhorn
chart: longhorn
repo: https://charts.rancher.io/
# valuesFrom:
# - configMapKeyRef:
# name: longhorn-chart-values
# # default to namespace of bundle
# namespace: fleet-local
# key: values.yaml
#
targetCustomizations:
- name: local
clusterSelector:
matchLabels:
management.cattle.io/cluster-display-name: local
helm:
values:
ingress:
enabled: true
host: longhorn-${ .ClusterAnnotations.ingressip }.sslip.io
annotations:
traefik.ingress.kubernetes.io/router.middlewares: longhorn-system-longhorn-basic-auth@kubernetescrd
kustomize:
dir: overlays/local

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- longhorn-basic-auth-middleware.yaml
- longhorn-ui-auth-secret.yaml

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: longhorn-basic-auth
namespace: longhorn-system
spec:
basicAuth:
secret: longhorn-ui-auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: longhorn-ui-auth
namespace: longhorn-system
data:
# admin:admin
users: |2
YWRtaW46JGFwcjEkYXpXL0J4czMkWHFoNDYyUGdZS251Y3ljT0JjeVJCMQoK
10 changes: 10 additions & 0 deletions fleet-examples/gitrepos/longhorn-gitrepo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: longhorn
namespace: fleet-local
spec:
repo: https://github.com/suse-edge/misc.git
branch: longhorn-fleet
paths:
- fleet-examples/fleets/longhorn/
9 changes: 7 additions & 2 deletions slemicro/get_kubeconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ else
while ! [ "$(curl -s -w '%{http_code}' -k -o /dev/null https://${RANCHERHOSTNAME}/healthz)" -eq 200 ]; do sleep 10; done
fi

# Login
TOKEN=$(curl -sk -X POST https://${RANCHERHOSTNAME}/v3-public/localProviders/local?action=login -H 'content-type: application/json' -d "{\"username\":\"admin\",\"responseType\": \"token\", \"password\": \"${RANCHERFINALPASSWORD}\"}" | jq -r .token)
TOKEN="null"
# Prevent a race condition while the rancher bootstrap is being applied
while [ ${TOKEN} == "null" ]; do
sleep 5
# Login
TOKEN=$(curl -sk -X POST https://${RANCHERHOSTNAME}/v3-public/localProviders/local?action=login -H 'content-type: application/json' -d "{\"username\":\"admin\",\"responseType\": \"token\", \"password\": \"${RANCHERFINALPASSWORD}\"}" | jq -r .token)
done

# Create a temp file
TMPKUBECONFIG=$(mktemp)
Expand Down

0 comments on commit 780a0a6

Please sign in to comment.