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

Add mock implementation of calico-node for scale testing. #9766

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .semaphore/push-images/mock-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: v1.0
name: Publish mock-node images
agent:
machine:
type: f1-standard-2
os_image: ubuntu2204

execution_time_limit:
minutes: 60

global_job_config:
env_vars:
- name: DEV_REGISTRIES
value: quay.io/calico docker.io/calico
secrets:
- name: docker
- name: quay-robot-calico+semaphoreci
prologue:
commands:
- checkout
# Semaphore is doing shallow clone on a commit without tags.
# unshallow it for GIT_VERSION:=$(shell git describe --tags --dirty --always)
- retry git fetch --unshallow
- echo $DOCKER_TOKEN | docker login --username "$DOCKER_USER" --password-stdin
- echo $QUAY_TOKEN | docker login --username "$QUAY_USER" --password-stdin quay.io
- export BRANCH_NAME=$SEMAPHORE_GIT_BRANCH

blocks:
- name: Publish mock-node images
dependencies: []
skip:
when: "branch !~ '.+'"
task:
jobs:
- name: Linux multi-arch
commands:
- if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make -C test-tools/mocknode cd CONFIRM=true; fi
- name: Publish mock-node multi-arch manifests
dependencies:
- Publish mock-node images
skip:
when: "branch !~ '.+'"
task:
jobs:
- name: Linux multi-arch manifests
commands:
- if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make -C test-tools/mocknode push-manifests-with-tag CONFIRM=true; fi
17 changes: 17 additions & 0 deletions .semaphore/semaphore-scheduled-builds.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .semaphore/semaphore.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .semaphore/semaphore.yml.d/03-promotions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ promotions:
pipeline_file: push-images/node.yml
auto_promote:
when: "branch =~ 'master|release-'"
- name: Push mock calico-node images
pipeline_file: push-images/mock-node.yml
auto_promote:
when: "branch =~ 'master|release-'"
- name: Push cni-plugin images
pipeline_file: push-images/cni-plugin.yml
auto_promote:
Expand Down
13 changes: 13 additions & 0 deletions .semaphore/semaphore.yml.d/blocks/60-mock-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: Mock node
run:
when: "${FORCE_RUN} or change_in(['/*', '/test-tools/mocknode/'], {exclude: ['/**/.gitignore', '/**/README.md', '/**/LICENSE']})"
dependencies:
- Prerequisites
task:
prologue:
commands:
- cd test-tools/mocknode
jobs:
- name: Mock node
commands:
- ../../.semaphore/run-and-monitor make-ci.log make ci
37 changes: 37 additions & 0 deletions test-tools/mocknode/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2023 Tigera, Inc. All rights reserved.
#
# 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.

FROM scratch AS source

ARG TARGETARCH

# And the mock-node itself...
COPY bin/test-tools/mocknode-${TARGETARCH} /usr/bin/mocknode

FROM calico/base

ARG GIT_VERSION=unknown

# Required labels for certification
LABEL description="Calico mock node for scale testing"
LABEL maintainer="[email protected]"
LABEL name="Calico mock node"
LABEL release="1"
LABEL summary="Calico mock node for scale testing"
LABEL vendor="Tigera"
LABEL version=${GIT_VERSION}

COPY --from=source / /

ENTRYPOINT ["/usr/bin/mocknode"]
95 changes: 95 additions & 0 deletions test-tools/mocknode/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
include ../../metadata.mk

PACKAGE_NAME?=github.com/projectcalico/calico/test-tools/mocknode

IMAGE_NAME ?=mock-node
BUILD_IMAGES ?=$(IMAGE_NAME)

###############################################################################
# Shortcut targets
###############################################################################
default: build image
test: ut ## Run the tests for the current platform/architecture

###############################################################################
# Variables controlling the image
###############################################################################
CONTAINER_CREATED=.container.created-$(ARCH)
# Files that go into the image
BINARY=./bin/test-tools/mocknode-$(ARCH)
# Files to be built
SRC_FILES=$(shell find . -name '*.go' | grep -v vendor) \
$(shell find ../../libcalico-go -name '*.go' | grep -v vendor)\
$(shell find ../../typha -name '*.go' | grep -v vendor)

###############################################################################
# Include ../../lib.Makefile
# Additions to EXTRA_DOCKER_ARGS need to happen before the include since
# that variable is evaluated when we declare DOCKER_RUN and siblings.
###############################################################################
include ../../lib.Makefile

###############################################################################
## Clean enough that a new release build will be clean
###############################################################################
.PHONY: clean
clean:
find . -name '*.created' -exec rm -f {} +
find . -name '*.created-$(ARCH)' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
rm -rf .go-pkg-cache bin
# Delete images that we built in this repo
-docker rmi $(IMAGE_NAME):latest-$(ARCH)

###############################################################################
# Building the binary
###############################################################################

LDFLAGS = -X main.VERSION=$(GIT_VERSION)

.PHONY: build-all
## Build the binaries for all architectures and platforms
build-all: $(addprefix bin/mocknode-,$(VALIDARCHES))

.PHONY: build
## Build the binary for the current architecture and platform
build: $(BINARY)
bin/test-tools/mocknode-amd64: ARCH=amd64
bin/test-tools/mocknode-%: $(SRC_FILES)
$(call build_binary, ./cmd/mocknode, $@)

###############################################################################
# Building the image
###############################################################################
## Create the image for the current ARCH
image: $(IMAGE_NAME)

## Create the images for all supported ARCHes
image-all: $(addprefix sub-image-,$(VALIDARCHES))
sub-image-%:
$(MAKE) image ARCH=$*

$(IMAGE_NAME): $(CONTAINER_CREATED)
$(CONTAINER_CREATED): Dockerfile $(BINARY)
$(DOCKER_BUILD) -t $(IMAGE_NAME):latest-$(ARCH) -f Dockerfile .
$(MAKE) retag-build-images-with-registries VALIDARCHES=$(ARCH) IMAGETAG=latest
touch $@

## Run the tests in a container. Useful for CI, Mac dev
ut:
mkdir -p report
$(DOCKER_RUN) $(CALICO_BUILD) /bin/bash -c "$(GIT_CONFIG_SSH) go test -v $(GOTEST_ARGS) ./..."

fv:
echo "Currently has no FV tests."

st:
echo "Currently has no STs."

###############################################################################
# CI/CD
###############################################################################
.PHONY: ci
ci: clean image test static-checks
## Deploys images to registry
cd: image-all cd-common
Loading
Loading