Skip to content
Merged
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
5 changes: 3 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ RUN cd /build-tools/kopium && \
cargo build --release --locked --offline && \
cp target/release/kopium /build/bin/kopium-0.23.0

RUN make crds-rs
RUN make crds-rs-all-features

# In debug builds, pre-build dependencies to avoid full rebuild on source changes.
RUN if [ "$build_type" = debug ]; then \
cargo build -p operator -p compute-pcrs -p register-server -p attestation-key-register; \
cargo build --all-features -p operator -p compute-pcrs -p register-server -p attestation-key-register; \
fi

COPY operator/operator/src operator/src
Expand All @@ -79,6 +79,7 @@ COPY operator/attestation-key-register/src attestation-key-register/src
RUN release_flag="" && \
if [ "$build_type" = release ]; then release_flag="--release"; fi && \
cargo build \
--all-features \
-p operator \
-p compute-pcrs \
-p register-server \
Expand Down
4 changes: 4 additions & 0 deletions tests/Cargo.lock

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

4 changes: 2 additions & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ k8s-openapi.workspace = true
kube.workspace = true
serde_json.workspace = true
tokio = "1.53.1"
trusted-cluster-operator-lib = { path = "../operator/lib" }
trusted-cluster-operator-test-utils = { path = "../operator/test_utils", features = ["virtualization"] }
trusted-cluster-operator-lib = { path = "../operator/lib", features = ["openshift"] }
trusted-cluster-operator-test-utils = { path = "../operator/test_utils", features = ["openshift", "virtualization"] }

[[test]]
name = "scale"
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ generate-downstream: $(CONTROLLER_GEN) $(OPENSHIFT_API_LOCAL)
$(call controller-gen,./$(OPENSHIFT_API_LOCAL)/machine/v1beta1,*{machines$(comma)azure*specs}*)

crds-rs-downstream: generate-downstream $(KOPIUM) $(CRD_RS_PATH)
cd $(MAKEFILE_DIR) && $(MAKE) crds-rs
cd $(MAKEFILE_DIR) && $(MAKE) generate-openshift && $(MAKE) crds-rs
$(MAKE) $(shell find $(CRD_YAML_PATH) -path $(OPENSHIFT_API_LOCAL) -prune -o -type f -print \
| sed -E 's|$(CRD_YAML_PATH)/.*_(.*)\.yaml|$(CRD_RS_PATH)/\1.rs|')

Expand Down
26 changes: 24 additions & 2 deletions tests/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use kube::{Api, core::Expression, runtime::wait::await_condition};
use serde_json::json;
use std::{collections::BTreeMap, time::Duration};
use tokio::{process::Command, time::timeout};
use trusted_cluster_operator_lib::endpoints::*;
use trusted_cluster_operator_lib::reference_values::*;
use trusted_cluster_operator_lib::{ApprovedImage, endpoints::*};
use trusted_cluster_operator_test_utils::virt::{NodeBackend, sh_exec};
use trusted_cluster_operator_test_utils::*;

Expand Down Expand Up @@ -109,15 +110,22 @@ impl NodeBackend for OpenShiftNode {
}
}

fn get_approved_image(machineconfig_name: &str) -> Result<String> {
let image_base = format!("{}-{}", machineconfig_name, get_env("APPROVED_IMAGE")?);
rfc1035(&image_base, OSIMAGE_RESOURCE_PREFIX)
}

fn create_mcp_object(machineset_name: &str) -> MachineConfigPool {
let match_expressions = MachineConfigPoolMachineConfigSelectorMatchExpressions {
key: MAPI_ROLE.to_string(),
operator: "In".to_string(),
values: Some(vec!["worker".to_string(), machineset_name.to_string()]),
};
let labels = BTreeMap::from([(MCP_APPROVED_IMAGE_LABEL.to_string(), String::new())]);
MachineConfigPool {
metadata: ObjectMeta {
name: Some(machineset_name.to_string()),
labels: Some(labels),
..Default::default()
},
spec: MachineConfigPoolSpec {
Expand Down Expand Up @@ -300,7 +308,7 @@ impl ScaleContext {
..Default::default()
},
spec: MachineConfigSpec {
os_image_url: Some(bootc_image),
os_image_url: Some(bootc_image.clone()),
..Default::default()
},
};
Expand All @@ -309,6 +317,14 @@ impl ScaleContext {
machineconfigs.create(&Default::default(), &mc).await?;
create_mcp(&test_ctx, &machineset_name, &mc_name).await?;

let approved_image_name = get_approved_image(&mc_name)?;
let images: Api<ApprovedImage> = Api::namespaced(client.clone(), test_ctx.namespace());
let info = format!("Waiting for ApprovedImage {approved_image_name} to be Committed");
test_ctx.info(&info);
let chk = approved_image_has_committed_condition;
let done = await_condition(images, &approved_image_name, chk);
timeout(scaled_duration(300), done).await.context(info)??;

let existing_secret_name = format!("{machineset_name}-user-data-managed");
let secrets: Api<Secret> = Api::namespaced(client.clone(), MAPI_NS);
wait_for_resource_created(&secrets, &existing_secret_name, scaled_timeout(120)).await?;
Expand Down Expand Up @@ -375,12 +391,15 @@ impl ScaleContext {
let client = self.test_ctx.client();
let machineset_name = &self.machineset_name;
let secret_name = format!("{machineset_name}-user-data-managed-cocl");
let image_name = get_approved_image(&self.mc_name)?;

self.test_ctx.info("Cleaning up");
let machinesets: Api<MachineSet> = Api::namespaced(client.clone(), MAPI_NS);
let machineconfigs: Api<MachineConfig> = Api::all(client.clone());
let mcps: Api<MachineConfigPool> = Api::all(client.clone());
let secrets: Api<Secret> = Api::namespaced(client.clone(), MAPI_NS);
let approvedimages: Api<ApprovedImage> =
Api::namespaced(client.clone(), self.test_ctx.namespace());

let dp = Default::default();
machinesets.delete(machineset_name, &dp).await?;
Expand All @@ -401,6 +420,9 @@ impl ScaleContext {
wait_for_resource_deleted(&secrets, &secret_name, duration).await?;
self.test_ctx
.info(format!("Secret {secret_name} has been deleted"));
wait_for_resource_deleted(&approvedimages, &image_name, duration).await?;
self.test_ctx
.info(format!("ApprovedImage {image_name} has been deleted"));

self.test_ctx.cleanup().await
}
Expand Down
Loading