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

feat: add SinkerContainer CRD #30

Merged
merged 3 commits into from
Jul 6, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ description = "Copy k8s resources (or parts thereof) across clusters"
clap = { version = "4.1", features = ["derive", "help", "env", "std"] }
futures = "0.3"
kube = { version = "0.80.0", features = ["runtime", "derive"] }
kube-derive = "0.80.0"
k8s-openapi = { version = "0.17.0", features = ["v1_26"] }
kubert = { version = "0.16.1", features = ["clap", "runtime", "server"] }
tokio = { version = "1.26", features = ["full"] }
anyhow = { version = "1", features = ["backtrace"] }
anyhow = { version = "1", features = ["backtrace"] }
tracing = "0.1"
schemars = "0.8.12"
serde = { version = "1", features = ["derive"] }
Expand Down
31 changes: 31 additions & 0 deletions manifests/crd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,35 @@ spec:
storage: true
subresources:
status: {}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: sinkercontainers.sinker.influxdata.io
spec:
group: sinker.influxdata.io
names:
categories: []
kind: SinkerContainer
plural: sinkercontainers
shortNames: []
singular: sinkercontainer
scope: Namespaced
versions:
- additionalPrinterColumns: []
name: v1alpha1
schema:
openAPIV3Schema:
description: This is a handy generic resource container for use as ResourceSync sources or targets
properties:
spec:
description: This is an arbitrary object
type: object
x-kubernetes-preserve-unknown-fields: true
required:
- spec
type: object
served: true
storage: true
subresources: {}

5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ async fn main() -> anyhow::Result<()> {
match &command {
Some(Commands::Manifests) => {
println!(
"{}",
serde_yaml::to_string(&sinker::resources::ResourceSync::crd()).unwrap()
"{}---\n{}",
serde_yaml::to_string(&sinker::resources::ResourceSync::crd()).unwrap(),
serde_yaml::to_string(&sinker::resources::SinkerContainer::crd_with_manual_schema()).unwrap()
);
}
None => {
Expand Down
41 changes: 41 additions & 0 deletions src/resources.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::{
CustomResourceDefinition, CustomResourceValidation, JSONSchemaProps,
};
use kube::{
core::{gvk::ParseGroupVersionError, GroupVersionKind, TypeMeta},
CustomResource,
Expand Down Expand Up @@ -98,3 +101,41 @@ pub struct SecretRef {
pub name: String,
pub key: String,
}

#[derive(CustomResource, Debug, Serialize, Deserialize, Default, Clone, JsonSchema)]
#[kube(
group = "sinker.influxdata.io",
version = "v1alpha1",
kind = "SinkerContainer",
namespaced,
schema = "disabled"
)]
#[serde(rename_all = "camelCase")]
pub struct SinkerContainerSpec {}

const MANUAL_SCHEMA: &str = r#"
Copy link
Contributor Author

@lukebond lukebond Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to jump through these hoops to get the x-kubernetes-preserve-unknown-fields field in there. taken from kubers example code here

description: This is a handy generic resource container for use as ResourceSync sources or targets
type: object
properties:
spec:
description: This is an arbitrary object
type: object
x-kubernetes-preserve-unknown-fields: true
required:
- spec
"#;

impl SinkerContainer {
pub fn crd_with_manual_schema() -> CustomResourceDefinition {
use kube::CustomResourceExt;
let schema: JSONSchemaProps = serde_yaml::from_str(MANUAL_SCHEMA).expect("invalid schema");

let mut crd = <Self as CustomResourceExt>::crd();
crd.spec.versions.iter_mut().for_each(|v| {
v.schema = Some(CustomResourceValidation {
open_api_v3_schema: Some(schema.clone()),
})
});
crd
}
}