Skip to content

Commit

Permalink
Merge pull request #30 from influxdata/feat/sinker-container
Browse files Browse the repository at this point in the history
feat: add SinkerContainer CRD
  • Loading branch information
lukebond authored Jul 6, 2023
2 parents 26b2cae + 3363fb9 commit 55bc050
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
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#"
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
}
}

0 comments on commit 55bc050

Please sign in to comment.