Skip to content

Commit

Permalink
chore: feature flag integration test hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
c-nixon authored and dkhokhlov committed Sep 29, 2023
1 parent 2089bd8 commit afc082b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 55 deletions.
65 changes: 16 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ RUST_LOG?=info
space := $(subst ,, )
comma := ,

FEATURES_ARG=$(if $(FEATURES),--features $(subst $(space),$(comma),$(FEATURES)))
FEATURES_ARG=$(if $(FEATURES),--features=$(subst $(space),$(comma),$(FEATURES)))

ifneq ($(NO_DEFAULT_FEATURES),)
FEATURES_ARG:=--no-default-features $(FEATURES_ARG)
endif

join-with = $(subst $(space),$1,$(strip $2))
join-with = $(if $(2),$(subst $(space),$1,$(strip $2)),$2)

_TAC= awk '{line[NR]=$$0} END {for (i=NR; i>=1; i--) print line[i]}'
TEST_RULES=
Expand Down Expand Up @@ -220,7 +220,8 @@ integration-test: ## Run integration tests using image with additional tools
$(DOCKER_JOURNALD_DISPATCH) "$(BUILD_ENV_DOCKER_ARGS) --env LOGDNA_INGESTION_KEY=$(LOGDNA_INGESTION_KEY) --env LOGDNA_HOST=$(LOGDNA_HOST) --env RUST_BACKTRACE=full --env RUST_LOG=$(RUST_LOG)" "cargo nextest run --no-fail-fast --retries=2 $(FEATURES_ARG) --manifest-path bin/Cargo.toml $(TESTS) $(TEST_THREADS_ARG)"

.PHONY:k8s-test
k8s-test: build-image-debian ## Run integration tests using k8s kind
k8s-test: ## Run integration tests using k8s kind
$(call build-image-command,debian,k8s_tests)
$(DOCKER) tag $(REPO):$(IMAGE_TAG) $(REPO):local
IMAGE_TAG=$(IMAGE_TAG) $(DOCKER_KIND_DISPATCH) $(K8S_TEST_CREATE_CLUSTER) $(RUST_IMAGE) "--env RUST_LOG=$(RUST_LOG)" "cargo nextest run --no-fail-fast --nocapture $(TARGET_DOCKER_ARG) --manifest-path bin/Cargo.toml --features k8s_tests"

Expand Down Expand Up @@ -383,9 +384,8 @@ DEB_VERSION=1
DEB_ARCH_NAME_x86_64=amd64
DEB_ARCH_NAME_aarch64=arm64

.PHONY:build-image
build-image: ## Build a docker image as specified in the Dockerfile
$(DOCKER) build . -t $(REPO):$(IMAGE_TAG) \
define build-image-command
$(DOCKER) build . -f $(if $(1),$(call join-with,.,Dockerfile $(1)),Dockerfile) -t $(REPO):$(IMAGE_TAG) \
$(PULL_OPTS) \
--progress=plain \
--platform=linux/${DEB_ARCH_NAME_${ARCH}} \
Expand All @@ -398,57 +398,24 @@ build-image: ## Build a docker image as specified in the Dockerfile
--build-arg TARGET_ARCH=$(ARCH) \
--build-arg BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \
--build-arg BUILD_VERSION=$(BUILD_VERSION) \
--build-arg FEATURES='$(FEATURES_ARG)' \
--build-arg FEATURES='$(if $(FEATURES_ARG),$(call join-with,$(comma),$(FEATURES_ARG),$(2)),--features $(2))' \
--build-arg REPO=$(REPO) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
--build-arg SCCACHE_BUCKET=$(SCCACHE_BUCKET) \
--build-arg SCCACHE_REGION=$(SCCACHE_REGION) \
--build-arg SCCACHE_ENDPOINT=$(SCCACHE_ENDPOINT)
endef

.PHONY:build-image-debian
build-image-debian: ## Build a docker image as specified in the Dockerfile.debian
$(DOCKER) build . -f Dockerfile.debian -t $(REPO):$(IMAGE_TAG) \
$(PULL_OPTS) \
--progress=plain \
--platform=linux/${DEB_ARCH_NAME_${ARCH}} \
--secret id=aws,src=$(AWS_SHARED_CREDENTIALS_FILE) \
--rm \
--build-arg BUILD_ENVS="$(BUILD_ENVS)" \
--build-arg BUILD_IMAGE=$(RUST_IMAGE) \
--build-arg TARGET=$(TARGET) \
--build-arg TARGET_DIR=$(TARGET_DIR) \
--build-arg BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \
--build-arg BUILD_VERSION=$(BUILD_VERSION) \
--build-arg FEATURES='$(FEATURES_ARG)' \
--build-arg REPO=$(REPO) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
--build-arg SCCACHE_BUCKET=$(SCCACHE_BUCKET) \
--build-arg SCCACHE_REGION=$(SCCACHE_REGION) \
--build-arg SCCACHE_ENDPOINT=$(SCCACHE_ENDPOINT)
define build-image-target
.PHONY:$(call join-with,-,build-image $(1))
$(call join-with,-,build-image $(1)): ## Build a docker image as specified in the $(call join-with,.,Dockerfile $(1))
$(call build-image-command,$(1))
endef

.PHONY:build-image-debug
build-image-debug: ## Build a docker image as specified in the Dockerfile.debug
$(DOCKER) build . -f Dockerfile.debug -t $(REPO):$(IMAGE_TAG) \
$(PULL_OPTS) \
--progress=plain \
--platform=linux/${DEB_ARCH_NAME_${ARCH}} \
--secret id=aws,src=$(AWS_SHARED_CREDENTIALS_FILE) \
--rm \
--build-arg BUILD_ENVS="$(BUILD_ENVS)" \
--build-arg BUILD_IMAGE=$(RUST_IMAGE) \
--build-arg TARGET=$(TARGET) \
--build-arg TARGET_DIR=$(TARGET_DIR) \
--build-arg BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \
--build-arg BUILD_VERSION=$(BUILD_VERSION) \
--build-arg FEATURES='$(FEATURES_ARG)' \
--build-arg REPO=$(REPO) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VCS_URL=$(VCS_URL) \
--build-arg SCCACHE_BUCKET=$(SCCACHE_BUCKET) \
--build-arg SCCACHE_REGION=$(SCCACHE_REGION) \
--build-arg SCCACHE_ENDPOINT=$(SCCACHE_ENDPOINT)
$(eval $(call build-image-target))
$(eval $(call build-image-target,debian))
$(eval $(call build-image-target,debug))

.PHONY:build-deb
build-deb: build-release
Expand Down
2 changes: 1 addition & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ dep_audit = ["auditable", "auditable-build"]
integration_tests = []
profiling = ["tikv-jemallocator/profiling"]
slow_tests = []
k8s_tests = []
k8s_tests = ["k8s/integration_tests"]
libjournald = ["journald/libjournald", "systemd" ]
journald_tests = ["journald/journald_tests", "systemd" ]
windows_service = []
Expand Down
15 changes: 10 additions & 5 deletions common/k8s/src/middleware/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use tracing::{debug, error, trace, warn};

#[cfg(feature = "integration_tests")]
lazy_static::lazy_static! {
static ref MOCK_NO_PODS: bool = std::env::var(config::env_vars::MOCK_NO_PODS).is_ok();
}
Expand Down Expand Up @@ -499,15 +500,19 @@ impl Middleware for K8sMetadata {
debug!("validate line from file: '{:?}'", file_name);
});
if let Some(parse_result) = parse_container_path(file_name) {
if !*MOCK_NO_PODS {
#[cfg(feature = "integration_tests")]
if *MOCK_NO_PODS {
return Err(MiddlewareError::Retry(self.name().into()));
}

if let Some(ref store) = self.state.lock().unwrap().store {
let obj_ref =
ObjectRef::new(&parse_result.pod_name).within(&parse_result.pod_namespace);
if let Some(ref store) = self.state.lock().unwrap().store {
if store.get(&obj_ref).is_some() {
return Ok(line);
}
if store.get(&obj_ref).is_some() {
return Ok(line);
}
}

// line does not have metadata yet
return Err(MiddlewareError::Retry(self.name().into()));
}
Expand Down

0 comments on commit afc082b

Please sign in to comment.