### Workload FlexVolume Setup Source: https://github.com/projectcalico/calico/blob/master/pod2daemon/README.md Example configuration for a Kubernetes workload demonstrating how to set up the FlexVolume driver for pod-to-daemon communication. ```yaml ... containers: volumeMounts: - mountPath: /tmp/udsver name: test-volume volumes: - name: test-volume flexVolume: driver: nodeagent/uds ``` -------------------------------- ### Build and Install confd from Source Source: https://github.com/projectcalico/calico/blob/master/confd/docs/installation.md Compile confd from source code and install it on the system. ```bash $ ./build $ sudo ./install ``` -------------------------------- ### Install Update Tools Source: https://github.com/projectcalico/calico/blob/master/typha/README.md Installs additional Go tools required for building Typha. Run this once before building. ```bash make update-tools ``` -------------------------------- ### Node-to-Node BGP Mesh Configuration Example Source: https://github.com/projectcalico/calico/blob/master/libcalico-go/docs/data-model.md JSON blob for controlling the automatic setup of a full node-to-node BGP mesh. If missing, it is enabled by default. ```json { "enabled": true|false } ``` -------------------------------- ### Install Ginkgo and Glide Source: https://github.com/projectcalico/calico/blob/master/node/README.md Install the Ginkgo testing framework and Glide dependency manager for Golang. These are required for running 'fv' packaged scoped tests. ```bash go get -u github.com/Masterminds/glide go get -u github.com/onsi/ginkgo/ginkgo ``` -------------------------------- ### Example: Run confd in Noop Mode with One-Time Execution Source: https://github.com/projectcalico/calico/blob/master/confd/docs/noop-mode.md This example demonstrates running confd with both the '-onetime' and '-noop' flags. Noop mode ensures that even if changes are detected, no files will be modified. ```bash confd -onetime -noop ``` -------------------------------- ### Install Tigera Operator Helm Chart Source: https://github.com/projectcalico/calico/blob/master/charts/tigera-operator/README.md Installs the Tigera Operator Helm chart into the specified namespace. ```bash helm install calico projectcalico/tigera-operator --namespace tigera-operator ``` -------------------------------- ### Run Unit Tests with Watch Mode Source: https://github.com/projectcalico/calico/blob/master/felix/README.md Start a ginkgo watch process that automatically re-runs relevant unit tests as files are updated. Requires ginkgo to be installed. ```bash make ut-watch ``` -------------------------------- ### Allocation Block Configuration Example Source: https://github.com/projectcalico/calico/blob/master/libcalico-go/docs/data-model.md JSON blob for Allocation Block configuration, detailing CIDR, host affinity, address allocations, and attributes. ```json { "cidr": "192.168.0.0/24", "affinity": "host:calico-host-01", "allocations": [0, 0, 0, 1, 2, 2, nil, nil, nil, nil, ...], "attributes": [ { "primary": "0cd47986-24ad-4c00-b9d3-5db9e5c02028", "secondary": { "container-id": "ba11f1de-fc4d-46fd-9f15-424f4ef05a3a", "email": "spike@projectcalico.org" } }, { "primary": "3465987ac-8975-987qr8789725875-98275", "secondary": { "container-name": "sandy_sabin", "email": "spike@projectcalico.org" } }, { "primary": "adf4589-11ab-c519-af11-098fade2190798", "secondary": { "rack": "01" } } ] } ``` -------------------------------- ### Add keys to etcd for complex example Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md Demonstrates creating nested directories and setting values within etcd, preparing data for a more complex template. ```bash etcdctl mkdir /services/web/cust1/ etcdctl mkdir /services/web/cust2/ etcdctl set /services/web/cust1/2 '{"IP": "10.0.0.2"}' etcdctl set /services/web/cust2/2 '{"IP": "10.0.0.4"}' etcdctl set /services/web/cust2/1 '{"IP": "10.0.0.3"}' etcdctl set /services/web/cust1/1 '{"IP": "10.0.0.1"}' ``` -------------------------------- ### IP Pool Configuration Example Source: https://github.com/projectcalico/calico/blob/master/libcalico-go/docs/data-model.md JSON blob for IP pool configuration, including CIDR, IPIP device name, and masquerade setting. ```json { "cidr": "", "ipip": "", "masquerade": true|false } ``` -------------------------------- ### JSON Allocation Handles Configuration Example Source: https://github.com/projectcalico/calico/blob/master/libcalico-go/docs/data-model.md JSON blob for Allocation Handle configuration, mapping Allocation Block CIDRs to the count of associated allocations. ```json { "id": , "block": { "192.168.10.0/24": 4, "2001:abcd:def0::/120": 3 } } ``` -------------------------------- ### Dump Conntrack Entries with nfnetlink Source: https://github.com/projectcalico/calico/blob/master/felix/nfnetlink/README.md This example demonstrates how to dump all conntrack entries to the screen using the nfnetlink package. It requires a handler to process each entry. ```go package main import ( "fmt" "github.com/tigera/nfnetlink" ) type Handler struct { count int } func (h *Handler) HandleConntrackEntry(cte nfnetlink.CtEntry) { fmt.Printf("%+v\n", cte) h.count++ } func ctdump() { handler := &Handler{} err := nfnetlink.ConntrackList(handler.HandleConntrackEntry) if err != nil { fmt.Println("Error: ", err) } fmt.Printf("Num entries returned %+v\n", handler.count) } func main() { fmt.Println("Running") ctdump() } ``` -------------------------------- ### Catalina start script with CATALINA_OPTS Source: https://github.com/projectcalico/calico/blob/master/confd/docs/tomcat-sample.md A minimal shell script to set CATALINA_OPTS environment variables for Tomcat memory settings, intended to be managed by confd. ```sh #!/bin/sh CATALINA_OPTS="-Xms{{getv "/Xms"}} -Xmx{{getv "/Xmx"}}" /usr/local/tomcat/bin/catalina.sh start ``` -------------------------------- ### RapidClient Example Scenarios Source: https://github.com/projectcalico/calico/blob/master/e2e/images/rapidclient/README.md Illustrates practical applications of RapidClient, including testing Maglev load balancing with consistent source ports, setting custom request timeouts, and enabling verbose mode for debugging. ```bash # Test Maglev load balancing with consistent source port ./rapidclient -url "http://service-ip:8080/shell?cmd=hostname" -port 12345 ``` ```bash # Test with custom timeout ./rapidclient -url "http://service-ip:8080/api/health" -timeout 10s ``` ```bash # Verbose mode for debugging ./rapidclient -url "http://service-ip:8080/shell?cmd=hostname" -port 12345 -v ``` -------------------------------- ### Display Release Tool Help Source: https://github.com/projectcalico/calico/blob/master/release/README.md Run this command to see the available options and usage instructions for the release tool. ```shell ./bin/release --help ``` -------------------------------- ### Basic RapidClient Usage Source: https://github.com/projectcalico/calico/blob/master/e2e/images/rapidclient/README.md Demonstrates fundamental command-line operations for RapidClient. Use these examples to send single requests, specify a source port, or enable verbose logging for detailed status and debug information. ```bash # Send a single request to a service ./rapidclient -url "http://10.96.0.1:8080/shell?cmd=hostname" ``` ```bash # Use a specific source port ./rapidclient -url "http://10.96.0.1:8080/shell?cmd=hostname" -port 12345 ``` ```bash # Verbose output with status information ./rapidclient -url "http://10.96.0.1:8080/shell?cmd=hostname" -v ``` -------------------------------- ### Get Key-Value Pair Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md The `get` function retrieves a KVPair by its key. It returns an error if the key is not found. ```go-template {{with get "/key"}} key: {{.Key}} value: {{.Value}} {{end}} ``` -------------------------------- ### Example confd Log Messages Source: https://github.com/projectcalico/calico/blob/master/confd/docs/logging.md These are example log messages generated by confd, illustrating different informational events during its operation. ```Bash 2013-11-03T19:04:53-08:00 confd[21356]: INFO SRV domain set to confd.io 2013-11-03T19:04:53-08:00 confd[21356]: INFO Starting confd 2013-11-03T19:04:53-08:00 confd[21356]: INFO etcd nodes set to http://etcd0.confd.io:4001, http://etcd1.confd.io:4001 2013-11-03T19:04:54-08:00 confd[21356]: INFO /tmp/myconf2.conf has md5sum ae5c061f41de8895b6ef70803de9a455 should be 50d4ce679e1cf13e10cd9de90d258996 2013-11-03T19:04:54-08:00 confd[21356]: INFO Target config /tmp/myconf2.conf out of sync 2013-11-03T19:04:54-08:00 confd[21356]: INFO Target config /tmp/myconf2.conf has been updated ``` -------------------------------- ### Example confd.toml Configuration Source: https://github.com/projectcalico/calico/blob/master/confd/docs/configuration-guide.md This TOML snippet demonstrates a typical configuration for confd, including backend settings, client certificates, logging level, polling interval, node list, and prefix. ```toml backend = "etcd" client_cert = "/etc/confd/ssl/client.crt" client_key = "/etc/confd/ssl/client.key" confdir = "/etc/confd" log-level = "debug" interval = 600 nodes = [ "http://127.0.0.1:4001", ] noop = false prefix = "/production" scheme = "https" srv_domain = "etcd.example.com" ``` -------------------------------- ### Get All Matching Key-Value Pairs Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md The `gets` function retrieves all KVPairs where the key matches the provided pattern. It returns an error if no keys are found. ```go-template {{range gets "/*"}} key: {{.Key}} value: {{.Value}} {{end}} ``` -------------------------------- ### Process Template with StackEngine Backend Source: https://github.com/projectcalico/calico/blob/master/confd/docs/quick-start-guide.md Run confd in one-time mode with StackEngine as the backend. Requires an auth token and node address. ```bash confd -onetime -backend stackengine -auth-token stackengine_api_key -node 192.168.255.210:8443 -scheme https ``` -------------------------------- ### Install Calico CRDs Source: https://github.com/projectcalico/calico/blob/master/charts/tigera-operator/README.md Installs the Calico Custom Resource Definitions (CRDs) using Helm template and kubectl apply. This is required for Calico versions 3.32 and later. ```bash helm template calico-crds projectcalico/crd.projectcalico.org.v1 | kubectl apply --server-side -f - ``` -------------------------------- ### Calico Installation Settings Source: https://github.com/projectcalico/calico/blob/master/charts/tigera-operator/README.md Configures general installation parameters for Calico, including Kubernetes provider and image pull secrets for the operator. Secrets must exist in the tigera-operator namespace. ```yaml # Configures general installation parameters for Calico. Schema is based # on the operator.tigera.io/Installation API documented # here: https://docs.tigera.io/calico/latest/reference/installation/api#installationspec installation: enabled: true kubernetesProvider: "" # imagePullSecrets are configured on all images deployed by the tigera-operator. # secrets specified here must exist in the tigera-operator namespace; they won't be created by the operator or helm. # imagePullSecrets are a slice of LocalObjectReferences, which is the same format they appear as on deployments. # # Example: --set installation.imagePullSecrets[0].name=my-existing-secret imagePullSecrets: [] # Configure the kubelet volume plugin path used by the CSI driver. # Set to "None" to disable the CSI driver. If this field is left unset, /var/lib/kubelet is used and CSI is enabled. kubeletVolumePluginPath: "None" ``` -------------------------------- ### Run Windows Connectivity Tests Source: https://github.com/projectcalico/calico/blob/master/process/testing/win-connections/README.md Execute the main script to set up the test environment and run connectivity checks between Linux and Windows nodes. Ensure prerequisites are met before running. ```bash ./run-tests.sh ``` -------------------------------- ### Install New Calico Helm Chart Source: https://github.com/projectcalico/calico/blob/master/charts/tigera-operator/README.md Install the new Calico helm chart into the 'tigera-operator' namespace after patching existing resources. This command assumes you are upgrading from a version prior to v3.23.0. ```bash helm install {{site.prodname | downcase}} projectcalico/tigera-operator --version {{site.data.versions[0].title}} --namespace tigera-operator ``` -------------------------------- ### BPF Test Matrix Prefix Example Source: https://github.com/projectcalico/calico/blob/master/felix/design/bpf-tests.md An example of a matrix prefix used in BPF functional tests to identify dataplane parameter combinations. This format is used to specify configurations for testing. ```text "ipv4 udp, ct=true, log=debug, tunnel=none, dsr=false" ``` -------------------------------- ### Generate Release Notes Source: https://github.com/projectcalico/calico/blob/master/release/RELEASING.md Run the make command to collect all release notes for a given version. This will create a file in the 'release-notes/' directory. ```sh make release-notes ``` -------------------------------- ### Install or Upgrade Calico CRDs Source: https://github.com/projectcalico/calico/blob/master/charts/crd.projectcalico.org.v1/README.md Use this command to add the Calico Helm repository and then template and apply the CRDs. This method is preferred over `helm install` for CRDs that may exceed size limits. ```bash helm repo add projectcalico https://docs.tigera.io/calico/charts helm template calico-crds projectcalico/crd.projectcalico.org.v1 | kubectl apply --server-side -f - ``` -------------------------------- ### Build and Test Commands Source: https://github.com/projectcalico/calico/blob/master/goldmane/CLAUDE.md Common make targets for building binaries, Docker images, running unit tests, benchmarks, and regenerating code artifacts. ```bash make build # Build Docker image make image # Run unit tests make ut # Run unit tests directly (faster iteration, no Docker) go test ./... # Run benchmarks make benchmark # Regenerate protobuf make protobuf # Regenerate mocks make gen-mocks ``` -------------------------------- ### Selector Expression Examples Source: https://github.com/projectcalico/calico/blob/master/libcalico-go/docs/data-model.md Illustrates various ways to construct selector expressions for matching endpoint labels in Calico policies. These examples cover comparisons, set membership, label presence, negation, and logical operations. ```string type == "webserver" && deployment == "prod" ``` ```string type in {"frontend", "backend"} ``` ```string deployment != "dev" ``` ```string ! has(label_name) ``` -------------------------------- ### Create Tigera Operator Namespace Source: https://github.com/projectcalico/calico/blob/master/charts/tigera-operator/README.md Creates the Kubernetes namespace where the Tigera Operator will be installed. ```bash kubectl create namespace tigera-operator ``` -------------------------------- ### Get parent directory Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md Use `dir` to find the parent directory of a given key. ```go-template {{with dir "/services/data/url"}} dir: {{.}} {{end}} ``` -------------------------------- ### Create Confd Directory Structure Source: https://github.com/projectcalico/calico/blob/master/confd/docs/quick-start-guide.md Create the necessary directories for confd configuration and templates. ```bash sudo mkdir -p /etc/confd/{conf.d,templates} ``` -------------------------------- ### Run Go Unit Tests Source: https://github.com/projectcalico/calico/blob/master/felix/CLAUDE.md Executes all Go unit tests using Ginkgo, including coverage. Skips specific packages. Pass GINKGO_ARGS for additional flags. ```bash make ut ``` -------------------------------- ### Get Current Datetime Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md The `datetime` function is an alias for `time.Now`, providing the current timestamp. ```go-template # Generated by confd {{datetime}} ``` -------------------------------- ### Get Base Key Name Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md The `base` function is an alias for `path.Base`, used to extract the last element of a path. ```go-template {{with get "/key"}} key: {{base .Key}} value: {{.Value}} {{end}} ``` -------------------------------- ### Clone Calico API Repository Source: https://github.com/projectcalico/calico/blob/master/release/RELEASING.md Clone the projectcalico/api repository to begin API updates. Ensure Github CLI is installed. ```sh git clone git@github.com:projectcalico/api.git ``` -------------------------------- ### Process Template with etcd Backend Source: https://github.com/projectcalico/calico/blob/master/confd/docs/quick-start-guide.md Run confd in one-time mode with etcd as the backend. ```bash confd -onetime -backend etcd -node http://127.0.0.1:4001 ``` -------------------------------- ### Process Template with Redis Backend Source: https://github.com/projectcalico/calico/blob/master/confd/docs/quick-start-guide.md Run confd in one-time mode with Redis as the backend. Specify the node address. ```bash confd -onetime -backend redis -node 192.168.255.210:6379 ``` -------------------------------- ### Get XDP Accepted Metadata Source: https://github.com/projectcalico/calico/blob/master/felix/design/bpf-xdp.md Retrieves the metadata indicating if a packet was accepted by XDP. This is called in the TC ingress hook. ```c xdp2tc_get_metadata(skb); ``` -------------------------------- ### Get Environment Variable Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md The `getenv` function retrieves the value of an environment variable. It returns an empty string if the variable is not set. ```bash export HOSTNAME `hostname` ``` ```go-template hostname: {{getenv "HOSTNAME"}} ``` -------------------------------- ### Build All Calico Images Source: https://github.com/projectcalico/calico/blob/master/DEVELOPER_GUIDE.md Run this command from the repository root to build all Calico container images. This process may take time. ```bash make image ``` -------------------------------- ### Build All Calico Binaries Source: https://github.com/projectcalico/calico/blob/master/DEVELOPER_GUIDE.md Create binaries for all supported architectures. The output binaries are located in 'bin/' or 'dist/' and follow a standard naming convention. ```bash make build-all ``` -------------------------------- ### Tag List Example Source: https://github.com/projectcalico/calico/blob/master/libcalico-go/docs/data-model.md A JSON list of tag strings. Each tag applies to endpoints associated with a policy and can be referenced by rules. ```json ["A", "B", "C", ...] ``` -------------------------------- ### Process Template with Environment Variables Backend Source: https://github.com/projectcalico/calico/blob/master/confd/docs/quick-start-guide.md Run confd in one-time mode using environment variables as the backend. ```bash confd -onetime -backend env ``` -------------------------------- ### Check Flow Emitter State Source: https://github.com/projectcalico/calico/blob/master/goldmane/CLAUDE.md Use this command to check the state of the flow emitter, which is typically active only in Calico Enterprise/Cloud installations. ```bash kubectl get configmap -n calico-system flow-emitter-state -o yaml ``` -------------------------------- ### Open Unit Test Coverage in Browser Source: https://github.com/projectcalico/calico/blob/master/felix/README.md Generate unit test coverage statistics and open the report in a web browser. Requires Go and GNU make. ```bash make cover-browser ``` -------------------------------- ### Get Value by Key with Default Source: https://github.com/projectcalico/calico/blob/master/confd/docs/templates.md Use `getv` with a default value to retrieve a key's value, returning the default if the key is not found. ```go-template value: {{getv "/key" "default_value"}} ```