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

Fix agentshift array case #33

Merged
merged 9 commits into from
Feb 16, 2022
Merged

Fix agentshift array case #33

merged 9 commits into from
Feb 16, 2022

Conversation

clux
Copy link
Member

@clux clux commented Feb 15, 2022

it's a bit hairy, but it might work now. i don't have an agent instance with that struct filled so can't know for sure. see linked issue.

Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
@clux clux linked an issue Feb 15, 2022 that may be closed by this pull request
Signed-off-by: clux <sszynrae@gmail.com>
@clux
Copy link
Member Author

clux commented Feb 16, 2022

ok, this now produces the following diff with before:

@@ -1,5 +1,6 @@
 use kube::CustomResource;
 use serde::{Serialize, Deserialize};
+use std::collections::BTreeMap;
 
 #[derive(CustomResource, Serialize, Deserialize, Clone, Debug)]
 #[kube(group = "agent-install.openshift.io", version = "v1beta1", kind = "Agent", plural = "agents")]
@@ -40,8 +41,8 @@
     pub ntpSources: Vec<AgentStatusNtpSources>,
     pub progress: Option<AgentStatusProgress>,
     pub role: Option<String>,
-    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
-    pub validationsInfo: BTreeMap<String, Array>,
+    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
+    pub validationsInfo: BTreeMap<String, AgentStatusValidationsInfo>,
 }
 
 #[derive(Serialize, Deserialize, Clone, Debug)]
@@ -172,4 +173,11 @@
     pub stageUpdateTime: Option<String>,
 }
 
+#[derive(Serialize, Deserialize, Clone, Debug)]
+pub struct AgentStatusValidationsInfo {
+    pub id: String,
+    pub message: String,
+    pub status: String,
+}
+

@clux clux marked this pull request as ready for review February 16, 2022 07:47
Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
@flaper87
Copy link
Contributor

I tested this PR and here's what it produces:

use kube::CustomResource;
use serde::{Serialize, Deserialize};
use std::collections::BTreeMap;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug)]
#[kube(group = "agent-install.openshift.io", version = "v1beta1", kind = "Agent", plural = "agents")]
#[kube(namespaced)]
#[kube(schema = "disabled")]
pub struct AgentSpec {
    pub approved: bool,
    pub clusterDeploymentName: Option<AgentClusterDeploymentName>,
    pub hostname: Option<String>,
    pub ignitionConfigOverrides: Option<String>,
    pub installation_disk_id: Option<String>,
    pub installerArgs: Option<String>,
    pub machineConfigPool: Option<String>,
    pub role: String,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentClusterDeploymentName {
    pub name: Option<String>,
    pub namespace: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatus {
    pub bootstrap: Option<bool>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub conditions: Vec<AgentStatusConditions>,
    pub debugInfo: Option<AgentStatusDebugInfo>,
    pub hostname: Option<String>,
    pub inventory: Option<AgentStatusInventory>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub ntpSources: Vec<AgentStatusNtpSources>,
    pub progress: Option<AgentStatusProgress>,
    pub role: Option<String>,
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub validationsInfo: BTreeMap<String, AgentStatusValidationsInfo>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusConditions {
    pub lastHeartbeatTime: Option<String>,
    pub lastTransitionTime: Option<String>,
    pub message: Option<String>,
    pub reason: Option<String>,
    pub status: String,
    pub r#type: String,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusDebugInfo {
    pub eventsURL: Option<String>,
    pub state: Option<String>,
    pub stateInfo: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventory {
    pub bmcAddress: Option<String>,
    pub bmcV6Address: Option<String>,
    pub boot: Option<AgentStatusInventoryBoot>,
    pub cpu: Option<AgentStatusInventoryCpu>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub disks: Vec<AgentStatusInventoryDisks>,
    pub hostname: Option<String>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub interfaces: Vec<AgentStatusInventoryInterfaces>,
    pub memory: Option<AgentStatusInventoryMemory>,
    pub reportTime: Option<String>,
    pub systemVendor: Option<AgentStatusInventorySystemVendor>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventoryBoot {
    pub currentBootMode: Option<String>,
    pub pxeInterface: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventoryCpu {
    pub architecture: Option<String>,
    pub clockMegahertz: Option<i64>,
    pub count: Option<i64>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub flags: Vec<String>,
    pub modelName: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventoryDisks {
    pub bootable: Option<bool>,
    pub byID: Option<String>,
    pub byPath: Option<String>,
    pub driveType: Option<String>,
    pub hctl: Option<String>,
    pub id: String,
    pub installationEligibility: Option<AgentStatusInventoryDisksInstallationEligibility>,
    pub ioPerf: Option<AgentStatusInventoryDisksIoPerf>,
    pub model: Option<String>,
    pub name: Option<String>,
    pub path: Option<String>,
    pub serial: Option<String>,
    pub sizeBytes: Option<i64>,
    pub smart: Option<String>,
    pub vendor: Option<String>,
    pub wwn: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventoryDisksInstallationEligibility {
    pub eligible: Option<bool>,
    pub notEligibleReasons: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventoryDisksIoPerf {
    pub syncDurationMilliseconds: Option<i64>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventoryInterfaces {
    pub biosDevName: Option<String>,
    pub clientID: Option<String>,
    pub flags: Vec<String>,
    pub hasCarrier: Option<bool>,
    pub ipV4Addresses: Vec<String>,
    pub ipV6Addresses: Vec<String>,
    pub macAddress: Option<String>,
    pub mtu: Option<i64>,
    pub name: Option<String>,
    pub product: Option<String>,
    pub speedMbps: Option<i64>,
    pub vendor: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventoryMemory {
    pub physicalBytes: Option<i64>,
    pub usableBytes: Option<i64>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusInventorySystemVendor {
    pub manufacturer: Option<String>,
    pub productName: Option<String>,
    pub serialNumber: Option<String>,
    pub r#virtual: Option<bool>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusNtpSources {
    pub sourceName: Option<String>,
    pub sourceState: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusProgress {
    pub currentStage: Option<String>,
    pub progressInfo: Option<String>,
    pub stageStartTime: Option<String>,
    pub stageUpdateTime: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AgentStatusValidationsInfo {
    pub id: String,
    pub message: String,
    pub status: String,
}

Looks correct 👍

Signed-off-by: clux <sszynrae@gmail.com>
Signed-off-by: clux <sszynrae@gmail.com>
@clux
Copy link
Member Author

clux commented Feb 16, 2022

ultimately still not sure if this is truly the right way to deal with this type of schema substructures - the crd does not actually use these objects in its status. but at the very least we have a new test case and have improved up a bunch of things.

@clux clux merged commit 6aaeb14 into main Feb 16, 2022
@clux clux deleted the fix-agentshift branch February 16, 2022 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kopium uses Array instead of Vec for array fields
2 participants