-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work to opensource guardian (#9849)
- Loading branch information
Showing
38 changed files
with
3,383 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- name: guardian | ||
run: | ||
when: "${FORCE_RUN} or change_in(['/*', '/guardian/'], {exclude: ['/**/.gitignore', '/**/README.md', '/**/LICENSE']})" | ||
execution_time_limit: | ||
minutes: 30 | ||
dependencies: | ||
- Prerequisites | ||
task: | ||
prologue: | ||
commands: | ||
- cd guardian | ||
jobs: | ||
- name: make ci | ||
commands: | ||
- ../.semaphore/run-and-monitor make-ci.log make ci | ||
- name: Build binary | ||
matrix: | ||
- env_var: ARCH | ||
values: | ||
- arm64 | ||
- ppc64le | ||
- s390x | ||
commands: | ||
- ../.semaphore/run-and-monitor image-$ARCH.log make build ARCH=$ARCH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
with-expecter: False | ||
inpackage: False | ||
dir: "{{.InterfaceDir}}/mocks" | ||
mockname: "{{.InterfaceName}}" | ||
outpkg: "mocks" | ||
filename: "{{.InterfaceName}}.go" | ||
packages: | ||
github.com/projectcalico/calico/guardian/pkg/tunnel: | ||
interfaces: | ||
SessionDialer: | ||
Session: | ||
net: | ||
config: | ||
outpkg: "{{.PackageName}}" | ||
dir: "pkg/thirdpartymocks/{{.PackagePath}}" | ||
interfaces: | ||
Conn: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
include ../metadata.mk | ||
|
||
PACKAGE_NAME ?= github.com/projectcalico/calico/guardian | ||
|
||
############################################# | ||
# Env vars related to packaging and releasing | ||
############################################# | ||
COMPONENTS ?=guardian | ||
GUARDIAN_IMAGE ?=guardian | ||
BUILD_IMAGES ?=$(GUARDIAN_IMAGE) | ||
|
||
############################################################################## | ||
# Include ../lib.Makefile before anything else | ||
# 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 | ||
|
||
########################################################################################## | ||
# Define some constants | ||
########################################################################################## | ||
BRANCH_NAME ?= $(PIN_BRANCH) | ||
|
||
BINDIR ?= bin | ||
SRC_FILES = $(shell find . -name '*.go') \ | ||
$(shell find ../api/pkg -name '*.go') \ | ||
$(shell find ../libcalico-go/lib/logutils -name '*.go') | ||
|
||
############################################# | ||
# Env vars related to building | ||
############################################# | ||
|
||
# Flags for building the binaries. | ||
# | ||
# We use -X to insert the version information into the placeholder variables | ||
# in the version package. | ||
LDFLAGS = -X $(PACKAGE_NAME)/pkg/version.BuildVersion=$(GIT_VERSION) \ | ||
-X $(PACKAGE_NAME)/pkg/version.BuildDate=$(DATE) \ | ||
-X $(PACKAGE_NAME)/pkg/version.GitDescription=$(GIT_DESCRIPTION) \ | ||
-X $(PACKAGE_NAME)/pkg/version.GitRevision=$(GIT_COMMIT) \ | ||
|
||
########################################################################################## | ||
# BUILD | ||
########################################################################################## | ||
build: $(BINDIR)/guardian-$(ARCH) | ||
|
||
.PHONY: $(BINDIR)/guardian-$(ARCH) | ||
$(BINDIR)/guardian-$(ARCH): $(SRC_FILES) | ||
ifeq ($(FIPS),true) | ||
$(call build_cgo_boring_binary, ./cmd/guardian/main.go, $@) | ||
else | ||
$(call build_binary, ./cmd/guardian/main.go, $@) | ||
endif | ||
|
||
gen-mocks: | ||
$(DOCKER_RUN) $(CALICO_BUILD) sh -c 'mockery' | ||
|
||
gen-files: gen-mocks | ||
|
||
############################################# | ||
# Docker Image | ||
############################################# | ||
GUARDIAN_CONTAINER_CREATED=.guardian.created-$(ARCH) | ||
|
||
# by default, build the image for the target architecture | ||
.PHONY: image-all | ||
image-all: $(addprefix sub-image-,$(VALIDARCHES)) | ||
sub-image-%: | ||
$(MAKE) image ARCH=$* | ||
|
||
.PHONY: image | ||
image: $(BUILD_IMAGES) | ||
|
||
$(GUARDIAN_IMAGE): $(GUARDIAN_CONTAINER_CREATED) | ||
$(GUARDIAN_CONTAINER_CREATED): docker-image/guardian/Dockerfile $(BINDIR)/guardian-$(ARCH) | ||
$(DOCKER_BUILD) -t $(GUARDIAN_IMAGE):latest-$(ARCH) -f docker-image/guardian/Dockerfile . | ||
$(MAKE) retag-build-images-with-registries VALIDARCHES=$(ARCH) IMAGETAG=latest BUILD_IMAGES=$(GUARDIAN_IMAGE) | ||
touch $@ | ||
|
||
############################################# | ||
# Run unit level tests | ||
############################################# | ||
.PHONY: ut | ||
## Run only Unit Tests. | ||
ut: | ||
$(DOCKER_GO_BUILD) go test ./... -cover -count 1 | ||
|
||
########################################################################################## | ||
# CI/CD | ||
########################################################################################## | ||
.PHONY: ci cd | ||
|
||
############################################# | ||
# Run CI cycle - build, test, etc. | ||
############################################# | ||
## Run all CI steps for build and test, likely other targets. | ||
ci: static-checks ut | ||
|
||
############################################# | ||
# Deploy images to registry | ||
############################################# | ||
## Run all CD steps, normally pushing images out to registries. | ||
cd: image-all cd-common | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2025 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. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/projectcalico/calico/guardian/pkg/config" | ||
"github.com/projectcalico/calico/guardian/pkg/daemon" | ||
"github.com/projectcalico/calico/guardian/pkg/version" | ||
) | ||
|
||
var ( | ||
versionFlag = flag.Bool("version", false, "Print version information") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
// For --version use case | ||
if *versionFlag { | ||
version.Version() | ||
os.Exit(0) | ||
} | ||
|
||
cfg, err := config.NewCalicoConfig() | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
|
||
logrus.Infof("Starting Calico Guardian %s", cfg.String()) | ||
daemon.Run(cfg.Config, cfg.Targets()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright (c) 2025 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 | ||
|
||
COPY bin/guardian-${TARGETARCH} /usr/bin/guardian | ||
|
||
FROM calico/base | ||
|
||
COPY --from=source / / | ||
|
||
USER 10001:10001 | ||
|
||
ENTRYPOINT ["/usr/bin/guardian"] |
Oops, something went wrong.