Skip to content

Commit df0b9e2

Browse files
authored
Automatic API update from tigera/calico-private master (#179)
2 parents 9cd5ef3 + ff8d891 commit df0b9e2

File tree

203 files changed

+65952
-1028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+65952
-1028
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ bin/
2222
/.vscode/
2323

2424
pkg/report
25+
*.orig

.semaphore/semaphore.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ blocks:
3030
task:
3131
jobs:
3232
- name: "make build / ci"
33+
env_vars:
34+
- name: CALICO_CRD_PATH
35+
value: config/crd/
36+
- name: CALICO_ADMISSION_POLICY_PATH
37+
value: admission/
3338
commands:
3439
- make build
3540
- make ci

Makefile

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# The tests in this directory use the projectcalico.org/v3 API group for CRDs.
2+
CALICO_API_GROUP ?= projectcalico.org/v3
3+
14
# If ../metadata.mk exists, we're running this logic from within the calico repository.
25
# If it does not, then we're in the api repo and we should use the local metadata.mk.
36
ifneq ("$(wildcard ../metadata.mk)", "")
@@ -12,6 +15,7 @@ LOCAL_CHECKS = lint-cache-dir check-copyright
1215
BINDIR ?= bin
1316
BUILD_DIR ?= build
1417
TOP_SRC_DIRS = pkg
18+
KIND_CONFIG = $(KIND_DIR)/kind-single.config
1519

1620
##############################################################################
1721
# Download and include ../lib.Makefile before anything else
@@ -35,6 +39,7 @@ DOCKER_RUN := mkdir -p ../.go-pkg-cache bin $(GOMOD_CACHE) && \
3539
--net=host \
3640
--init \
3741
$(EXTRA_DOCKER_ARGS) \
42+
$(DOCKER_GIT_WORKTREE_ARGS) \
3843
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
3944
-e GOCACHE=/go-cache \
4045
$(GOARCH_FLAGS) \
@@ -54,6 +59,18 @@ build: gen-files examples
5459
# Regenerate all files if the gen exes changed or any "types.go" files changed
5560
.PHONY: gen-files
5661
gen-files .generate_files: lint-cache-dir clean-generated
62+
# Generate CRDs without descriptions
63+
$(DOCKER_RUN) $(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) controller-gen crd:allowDangerousTypes=true,crdVersions=v1,deprecatedV1beta1CompatibilityPreserveUnknownFields=false,maxDescLen=0 paths=./pkg/apis/... output:crd:dir=config/crd/'
64+
# Remove the first yaml separator line.
65+
$(DOCKER_RUN) $(CALICO_BUILD) sh -c 'find ./config/crd -name "*.yaml" | xargs sed -i 1d'
66+
# Run prettier to fix indentation
67+
docker run --rm --user $(id -u):$(id -g) -v $(CURDIR)/config/crd/:/work/config/crd/ tmknom/prettier --write --parser=yaml /work
68+
# Patch in manual tweaks to the generated CRDs.
69+
# - Add nullable to IPAM block allocations field to allow null values in the allocations array.
70+
# - Remove the profiles CRD. Profiles are backed by Namespaces in Kubernetes and the CRD is not needed.
71+
patch -p2 < patches/0001-Add-nullable-to-IPAM-block-allocations-field.patch
72+
rm -f config/crd/projectcalico.org_profiles.yaml
73+
5774
# Generate defaults
5875
$(DOCKER_RUN) $(CALICO_BUILD) \
5976
sh -c '$(GIT_CONFIG_SSH) defaulter-gen \
@@ -62,6 +79,7 @@ gen-files .generate_files: lint-cache-dir clean-generated
6279
--extra-peer-dirs "$(PACKAGE_NAME)/pkg/apis/projectcalico/v3" \
6380
--output-file zz_generated.defaults.go \
6481
"$(PACKAGE_NAME)/pkg/apis/projectcalico/v3"'
82+
6583
# Generate deep copies
6684
$(DOCKER_RUN) $(CALICO_BUILD) \
6785
sh -c '$(GIT_CONFIG_SSH) deepcopy-gen \
@@ -70,6 +88,13 @@ gen-files .generate_files: lint-cache-dir clean-generated
7088
--bounding-dirs $(PACKAGE_NAME) \
7189
--output-file zz_generated.deepcopy.go \
7290
"$(PACKAGE_NAME)/pkg/apis/projectcalico/v3"'
91+
$(DOCKER_RUN) $(CALICO_BUILD) \
92+
sh -c '$(GIT_CONFIG_SSH) deepcopy-gen \
93+
--v 1 --logtostderr \
94+
--go-header-file "/go/src/$(PACKAGE_NAME)/hack/boilerplate/boilerplate.go.txt" \
95+
--bounding-dirs $(PACKAGE_NAME) \
96+
--output-file zz_generated.deepcopy.go \
97+
"$(PACKAGE_NAME)/pkg/apis/usage.tigera.io/v1"'
7398

7499
# generate all pkg/client contents
75100
$(DOCKER_RUN) $(CALICO_BUILD) \
@@ -135,9 +160,14 @@ WHAT?=.
135160
GINKGO_FOCUS?=.*
136161

137162
.PHONY:ut
138-
ut:
139-
$(DOCKER_RUN) --privileged $(CALICO_BUILD) \
140-
sh -c 'cd /go/src/$(PACKAGE_NAME) && ginkgo -r -focus="$(GINKGO_FOCUS)" $(WHAT)'
163+
ut: kind-cluster-create
164+
mkdir -p report
165+
$(DOCKER_RUN) \
166+
--privileged \
167+
-e KUBECONFIG=/kubeconfig.yaml \
168+
-v $(KIND_KUBECONFIG):/kubeconfig.yaml \
169+
$(CALICO_BUILD) \
170+
sh -c 'cd /go/src/$(PACKAGE_NAME) && ginkgo -r --focus="$(GINKGO_FOCUS)" $(WHAT)'
141171

142172
## Check if generated files are out of date
143173
.PHONY: check-generated-files
@@ -154,4 +184,4 @@ check-generated-files: .generate_files
154184
###############################################################################
155185
.PHONY: ci
156186
## Run what CI runs
157-
ci: clean check-generated-files build ut static-checks
187+
ci: clean check-generated-files static-checks build ut
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This MutatingAdmissionPolicy defaults the types/policyTypes field on Calico policy resources.
2+
apiVersion: admissionregistration.k8s.io/v1beta1
3+
kind: MutatingAdmissionPolicy
4+
metadata:
5+
name: "policytypes.policy.projectcalico.org"
6+
spec:
7+
paramKind:
8+
kind: NetworkPolicy
9+
apiVersion: projectcalico.org/v3
10+
matchConditions:
11+
# Apply this mutation only if the 'types' field is missing (or policyTypes for stagednetworkpolicies).
12+
- name: missing-types
13+
expression: "!has(object.spec.types) && !has(object.spec.policyTypes)"
14+
matchConstraints:
15+
resourceRules:
16+
- apiGroups: ["projectcalico.org"]
17+
apiVersions: ["v3"]
18+
operations: ["CREATE", "UPDATE"]
19+
resources:
20+
- networkpolicies
21+
- globalnetworkpolicies
22+
- stagednetworkpolicies
23+
- stagedglobalnetworkpolicies
24+
- stagedkubernetesnetworkpolicies
25+
failurePolicy: Fail
26+
reinvocationPolicy: IfNeeded
27+
variables:
28+
# Determine the policy types based on the presence of ingress and egress rules.
29+
# If both are present, set types to ["Ingress", "Egress"].
30+
# If only ingress is present, set types to ["Ingress"].
31+
# If only egress is present, set types to ["Egress"].
32+
# If neither is present, default to ["Ingress"] for backward compatibility with policies from before types were required.
33+
- name: defaultTypes
34+
expression: |
35+
(has(object.spec.ingress) && has(object.spec.egress)) ? ["Ingress", "Egress"] :
36+
has(object.spec.egress) ? ["Egress"] : ["Ingress"]
37+
38+
# The logic for StagedKubernetesNetworkPolicy is slightly different from the above:
39+
# - If both ingress and egress are present, set types to ["Ingress", "Egress"].
40+
# - If only ingress is present, set types to ["Ingress"].
41+
# - If only egress is present, set types to ["Ingress", "Egress"].
42+
# - If neither is present, default to ["Ingress"] for backward compatibility.
43+
- name: defaultKubeTypes
44+
expression: |
45+
(has(object.spec.ingress) && has(object.spec.egress)) ? ["Ingress", "Egress"] :
46+
has(object.spec.egress) ? ["Ingress", "Egress"] : ["Ingress"]
47+
48+
mutations:
49+
# Add the calculated 'types' field to the spec.
50+
- patchType: "JSONPatch"
51+
jsonPatch:
52+
expression: |
53+
[
54+
JSONPatch{
55+
op: "add",
56+
path: object.kind == "StagedKubernetesNetworkPolicy" ? "/spec/policyTypes" : "/spec/types",
57+
value: object.kind == "StagedKubernetesNetworkPolicy" ? variables.defaultKubeTypes : variables.defaultTypes
58+
}
59+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This MutatingAdmissionPolicyBinding binds the policy types defaulting mutation to the relevant resources.
2+
apiVersion: admissionregistration.k8s.io/v1beta1
3+
kind: MutatingAdmissionPolicyBinding
4+
metadata:
5+
name: set-policytypes-binding
6+
spec:
7+
policyName: policytypes.policy.projectcalico.org
8+
matchResources:
9+
resourceRules:
10+
- apiGroups: ["projectcalico.org"]
11+
apiVersions: ["v3"]
12+
operations: ["CREATE", "UPDATE"]
13+
resources:
14+
- networkpolicies
15+
- globalnetworkpolicies
16+
- stagednetworkpolicies
17+
- stagedglobalnetworkpolicies
18+
- stagedkubernetesnetworkpolicies
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This MutatingAdmissionPolicy sets the projectcalico.org/tier label on policy resources
2+
# to match the spec.tier field, defaulting to "default" if not specified.
3+
apiVersion: admissionregistration.k8s.io/v1beta1
4+
kind: MutatingAdmissionPolicy
5+
metadata:
6+
name: "tierlabel.policy.projectcalico.org"
7+
spec:
8+
matchConstraints:
9+
resourceRules:
10+
- apiGroups: ["projectcalico.org"]
11+
apiVersions: ["v3"]
12+
operations: ["CREATE", "UPDATE"]
13+
resources:
14+
- networkpolicies
15+
- globalnetworkpolicies
16+
- stagednetworkpolicies
17+
- stagedglobalnetworkpolicies
18+
failurePolicy: Fail
19+
reinvocationPolicy: IfNeeded
20+
variables:
21+
- name: tierValue
22+
expression: |
23+
has(object.spec.tier) && object.spec.tier != "" ? object.spec.tier : "default"
24+
mutations:
25+
# Set the projectcalico.org/tier label to match spec.tier.
26+
# Uses ~1 encoding for the / in the label key per RFC 6901 (JSON Pointer).
27+
- patchType: "JSONPatch"
28+
jsonPatch:
29+
expression: |
30+
has(object.metadata.labels) ?
31+
[JSONPatch{op: "add", path: "/metadata/labels/projectcalico.org~1tier", value: variables.tierValue}] :
32+
[
33+
JSONPatch{op: "add", path: "/metadata/labels", value: {}},
34+
JSONPatch{op: "add", path: "/metadata/labels/projectcalico.org~1tier", value: variables.tierValue}
35+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This MutatingAdmissionPolicyBinding binds the tier label mutation to the relevant resources.
2+
apiVersion: admissionregistration.k8s.io/v1beta1
3+
kind: MutatingAdmissionPolicyBinding
4+
metadata:
5+
name: set-tier-label-binding
6+
spec:
7+
policyName: tierlabel.policy.projectcalico.org
8+
matchResources:
9+
resourceRules:
10+
- apiGroups: ["projectcalico.org"]
11+
apiVersions: ["v3"]
12+
operations: ["CREATE", "UPDATE"]
13+
resources:
14+
- networkpolicies
15+
- globalnetworkpolicies
16+
- stagednetworkpolicies
17+
- stagedglobalnetworkpolicies

0 commit comments

Comments
 (0)