Skip to content

Commit ddf474a

Browse files
committed
fixup! fix: Sync CRD informer caches for CRS
1 parent ba4026b commit ddf474a

7 files changed

Lines changed: 198 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ jobs:
169169
run: |
170170
make build
171171
172+
ci-peripheral-tests:
173+
name: ci-e2e-tests
174+
runs-on: ubuntu-latest
175+
steps:
176+
- name: Check out code into the Go module directory
177+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
178+
179+
- name: Set up Go 1.x
180+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
181+
with:
182+
go-version: ${{ env.GO_VERSION }}
183+
id: go
184+
185+
- name: Peripheral tests
186+
run: |
187+
./tests/crs-cache-sync.sh
188+
172189
ci-e2e-tests:
173190
name: ci-e2e-tests
174191
runs-on: ubuntu-latest

tests/crs-cache-sync.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# shellcheck disable=SC1091
6+
source ./utils.sh
7+
8+
setup_kind
9+
setup_kubectl
10+
11+
# Delete and recreate the kind cluster
12+
kind delete cluster || true
13+
kind create cluster
14+
15+
# Timed background tasks
16+
(
17+
sleep 60
18+
echo "Script timed out after 60 seconds"
19+
kill $$
20+
) &
21+
22+
(
23+
sleep 20
24+
echo "Deleting CRD after 20 seconds"
25+
kubectl delete -f testdata/crd.yaml || true
26+
) &
27+
28+
(
29+
sleep 30
30+
echo "Checking telemetry data for out-of-sync errors after 30 seconds"
31+
curl -s "http://localhost:8081/metrics" | grep -E 'kube_state_metrics_(list|watch)_total\{[^}]*result="error"[^}]*\} 1' && echo "Found error in telemetry!" || echo "No error found"
32+
) &
33+
34+
# Apply CRD and CR
35+
kubectl apply -f testdata/crd.yaml
36+
kubectl apply -f testdata/cr.yaml
37+
38+
# Run the custom resource state binary in blocking mode
39+
go run . --kubeconfig="$KUBECONFIG" --custom-resource-state-config-file ~/testdata/ksm-crs.yaml --custom-resource-state-only

tests/e2e.sh

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
# shellcheck disable=SC1091
18+
source ./utils.sh
19+
1720
set -x
1821
set -e
1922
set -o pipefail
@@ -31,7 +34,6 @@ KUBE_STATE_METRICS_CURRENT_IMAGE_NAME="registry.k8s.io/kube-state-metrics/kube-s
3134
KUBE_STATE_METRICS_IMAGE_NAME="registry.k8s.io/kube-state-metrics/kube-state-metrics-${ARCH}"
3235
E2E_SETUP_KIND=${E2E_SETUP_KIND:-}
3336
E2E_SETUP_KUBECTL=${E2E_SETUP_KUBECTL:-}
34-
KIND_VERSION=v0.25.0
3537
SUDO=${SUDO:-}
3638

3739
OS=$(uname -s | awk '{print tolower($0)}')
@@ -45,18 +47,6 @@ function finish() {
4547
kubectl delete -f tests/manifests/ || true
4648
}
4749

48-
function setup_kind() {
49-
curl -sLo kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${OS}-${ARCH}" \
50-
&& chmod +x kind \
51-
&& ${SUDO} mv kind /usr/local/bin/
52-
}
53-
54-
function setup_kubectl() {
55-
curl -sLo kubectl https://dl.k8s.io/release/"$(curl -sL https://dl.k8s.io/release/stable.txt)"/bin/"${OS}"/"${ARCH}"/kubectl \
56-
&& chmod +x kubectl \
57-
&& ${SUDO} mv kubectl /usr/local/bin/
58-
}
59-
6050
[[ -n "${E2E_SETUP_KIND}" ]] && setup_kind
6151

6252
kind version
@@ -66,8 +56,6 @@ kind version
6656
mkdir "${HOME}"/.kube || true
6757
touch "${HOME}"/.kube/config
6858

69-
export KUBECONFIG=$HOME/.kube/config
70-
7159
kind create cluster --image="${NODE_IMAGE_NAME}:${KUBERNETES_VERSION}"
7260

7361
kind export kubeconfig
@@ -99,25 +87,7 @@ function kube_state_metrics_up() {
9987
exit 1
10088
fi
10189
}
102-
function kube_pod_up() {
103-
is_pod_running="false"
10490

105-
for _ in {1..90}; do # timeout for 3 minutes
106-
kubectl get pods -A | grep "$1" 1>/dev/null 2>&1
107-
if [[ $? -ne 1 ]]; then
108-
is_pod_running="true"
109-
break
110-
fi
111-
112-
echo "waiting for pod $1 to come up"
113-
sleep 2
114-
done
115-
116-
if [[ ${is_pod_running} == "false" ]]; then
117-
echo "Pod does not show up within 3 minutes"
118-
exit 1
119-
fi
120-
}
12191

12292
function test_daemonset() {
12393
sed -i "s|${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME}:v.*|${KUBE_STATE_METRICS_IMAGE_NAME}:${KUBE_STATE_METRICS_IMAGE_TAG}|g" ./examples/daemonsetsharding/deployment.yaml

tests/testdata/cr.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: contoso.com/v1alpha1
2+
kind: MyPlatform
3+
metadata:
4+
name: test-dotnet-app
5+
labels:
6+
foo: "1"
7+
bar: "2"
8+
resourceVersion: "0061"
9+
spec:
10+
appId: testdotnetapp
11+
language: csharp
12+
os: linux
13+
instanceSize: small
14+
environmentType: dev
15+
replicas: 3
16+
features:
17+
- logging
18+
- metrics
19+
- autoscaling

tests/testdata/crd.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: myplatforms.contoso.com
5+
spec:
6+
group: contoso.com
7+
names:
8+
plural: myplatforms
9+
singular: myplatform
10+
kind: MyPlatform
11+
shortNames:
12+
- myp
13+
scope: Namespaced
14+
versions:
15+
- name: v1alpha1
16+
served: true
17+
storage: true
18+
schema:
19+
openAPIV3Schema:
20+
type: object
21+
properties:
22+
spec:
23+
type: object
24+
properties:
25+
appId:
26+
type: string
27+
language:
28+
type: string
29+
enum:
30+
- csharp
31+
- python
32+
- go
33+
os:
34+
type: string
35+
enum:
36+
- windows
37+
- linux
38+
instanceSize:
39+
type: string
40+
enum:
41+
- small
42+
- medium
43+
- large
44+
environmentType:
45+
type: string
46+
enum:
47+
- dev
48+
- test
49+
- prod
50+
replicas:
51+
type: integer
52+
minimum: 1
53+
features:
54+
type: array
55+
items:
56+
type: string
57+
required: ["appId", "language", "environmentType"]
58+
required: ["spec"]

tests/testdata/ksm-crs.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
kind: CustomResourceStateMetrics
2+
spec:
3+
resources:
4+
- groupVersionKind:
5+
group: "contoso.com"
6+
version: "v1alpha1"
7+
kind: "MyPlatform"
8+
metrics:
9+
- name: "foo_info"
10+
help: "foo_help_"
11+
each:
12+
type: Info
13+
info:
14+
labelsFromPath:
15+
"foo_annotation_value": [metadata,annotations,foo=bar]
16+
"name": [metadata,name]
17+

tests/utils.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
export KUBECONFIG=$HOME/.kube/config
4+
5+
KIND_VERSION=v0.25.0
6+
SUDO=${SUDO:-}
7+
OS=$(uname -s | awk '{print tolower($0)}')
8+
OS=${OS:-linux}
9+
case $(uname -m) in
10+
aarch64) ARCH="arm64";;
11+
x86_64) ARCH="amd64";;
12+
*) ARCH="$(uname -m)";;
13+
esac
14+
15+
function setup_kind() {
16+
curl -sLo kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${OS}-${ARCH}" \
17+
&& chmod +x kind \
18+
&& ${SUDO} mv kind /usr/local/bin/
19+
}
20+
21+
function setup_kubectl() {
22+
curl -sLo kubectl https://dl.k8s.io/release/"$(curl -sL https://dl.k8s.io/release/stable.txt)"/bin/"${OS}"/"${ARCH}"/kubectl \
23+
&& chmod +x kubectl \
24+
&& ${SUDO} mv kubectl /usr/local/bin/
25+
}
26+
27+
function kube_pod_up() {
28+
is_pod_running="false"
29+
30+
for _ in {1..90}; do # timeout for 3 minutes
31+
kubectl get pods -A | grep "$1" 1>/dev/null 2>&1
32+
if [[ $? -ne 1 ]]; then
33+
is_pod_running="true"
34+
break
35+
fi
36+
37+
echo "waiting for pod $1 to come up"
38+
sleep 2
39+
done
40+
41+
if [[ ${is_pod_running} == "false" ]]; then
42+
echo "Pod does not show up within 3 minutes"
43+
exit 1
44+
fi
45+
}

0 commit comments

Comments
 (0)