Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic installation of Calico on workload clusters #14

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions config/samples/calico-cni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ metadata:
name: calico-cni
spec:
clusterSelector:
matchLabels:
calicoCNI: enabled
# Target workload clusters with specific labels.
# matchLabels:
# calicoCNI: enabled
# Target all workload clusters.
matchLabels: {}
releaseName: calico
repoURL: https://projectcalico.docs.tigera.io/charts
repoURL: https://docs.tigera.io/calico/charts
chartName: tigera-operator
values: |
namespace: kube-system
valuesTemplate: |
installation:
cni:
type: Calico
Expand Down
40 changes: 38 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,49 @@ enable_providers:
- helm
```

#### 3. Set up automatic installation for calico. (Optional)

#### 3. Run Tilt
Calico is automatically installed when workload clusters are started.

From `src/cluster-api-addon-provider-helm` run:

```bash
$ ./hack/setup-calico-autoinstallation.sh
```

See [Automatically install calico in workload clusters with Tilt](#automatically-install-calico-in-workload-clusters-with-tilt) for more details.

#### 4. Run Tilt

From `src/cluster-api` run:

```bash
$ make tilt-up
```

From within Tilt, you should be able to see the CAAPH controller running alongside the Cluster API controllers with the CRDs installed.
From within Tilt, you should be able to see the CAAPH controller running alongside the Cluster API controllers with the CRDs installed.

### Automatically install calico in workload clusters with Tilt

Automatically install [calico](https://docs.tigera.io/calico) in workload clusters using the [yaml manifest](https://github.com/kubernetes-sigs/cluster-api-addon-provider-helm/blob/main/config/samples/calico-cni.yaml) provided by CAAPH.
The setup script(`setup-calico-autoinstallation.sh`) generates a tiltfile to incorporate the above yaml manifest as a Tilt resource.

**Setup script (`setup-calico-autoinstallation.sh`) Summary:**
- Generate the tiltfile to incorporate the above yaml manifest as a Tilt resource.
- Refer to [Tiltfile API Reference](https://docs.tilt.dev/api.html) for functions used in the tiltfile.
- The tiltfile is output to the `src/cluster-api/tilt.d` directory.
- Run `make tilt-up` ,files under the `src/cluster-api/tilt.d` are automatically started. (excluding subdirectories)


The yaml manifest (`src/cluster-api-addon-provider-helm/config/samples/calico-cni.yaml`) is changed, it is redeployed by Tilt.

**For the target workload clusters**
The yaml manifest (`src/cluster-api-addon-provider-helm/config/samples/calico-cni.yaml`) is for all workload clusters. <br>

An example targeting workload clusters with a specific label.
```yaml
spec:
clusterSelector:
matchLabels:
cni: calico
```
37 changes: 37 additions & 0 deletions hack/setup-calico-autoinstallation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Copyright 2023 The Kubernetes Authors.
#
# 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.

set -o errexit
set -o nounset

BASE_DIR=$(dirname "$0")
CAPI_DIR=${BASE_DIR}/../../cluster-api
TILTD_DIR=${CAPI_DIR}/tilt.d
TILT_FILE=${TILTD_DIR}/calico_tiltfile

# Check and create directories.
[ -d "${CAPI_DIR}" ] && [ ! -d "${TILTD_DIR}" ] && mkdir -p "${TILTD_DIR}"

# Generate the calico_tiltfile.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems reasonable to me and I'll test it out on my end when I have some time. I wonder if we should instead set up a separate Tiltfile for CAAPH instead and include this in there instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is my understanding correct that prepare the Tiltfile in advance and copy it to tilt.d directory?.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the Tiltfile is where we would run tilt up from. Currently, we're running it from a clone of the Cluster API repo, but for other providers like Cluster API Provider for Azure, it has its own Tiltfile and doesn't require CAPI to be present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth bringing up in the CAPI office hours on how we could handle that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm with you. Let us discuss it during the CAPI office hours.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hama-25179 I tested it out and it seems to work, just make sure you run chmod +x setup-calico-autoinstallation.sh and commit that to the branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for testing. I set executable permission to the script.

cat <<EOF > "${TILT_FILE}"
# -*- mode: Python -*-

yaml_file = "../../cluster-api-addon-provider-helm/config/samples/calico-cni.yaml"
k8s_yaml(yaml_file)

# Create k8s resource.
k8s_resource(objects=['calico-cni:helmchartproxy'], labels = ['CAAPH.helmchartproxy'], resource_deps = ['caaph_controller','uncategorized'],new_name='calico-cni')
EOF