Skip to content
Open
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
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
serde = "1.0.204"
serde_json = "1.0.122"

[dependencies.thiserror]
optional = true
version = "2.0.11"

[dependencies.jsonptr]
optional = true
version = "0.7.1"

[dependencies.semver]
optional = true
features = ["serde"]
version = "1.0"

[dependencies.k8s-openapi]
features = ["schemars", "latest"]
version = "0.24.0"
Expand All @@ -20,3 +33,6 @@
readme = "README.md"
repository = "https://github.com/capi-samples/cluster-api-rs"
version = "1.9.5"

[features]
contract = ["dep:semver", "dep:jsonptr", "dep:thiserror"]
56 changes: 56 additions & 0 deletions src/contract/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2022 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use super::types::Path;

// BootstrapContract encodes information about the Cluster API contract for bootstrap objects.
pub struct BootstrapContract;

// Bootstrap provide access to the information about the Cluster API contract for bootstrap objects.
pub fn bootstrap() -> BootstrapContract {
BootstrapContract
}

impl BootstrapContract {
// Ready provide access to status.ready field in a bootstrap object.
pub fn ready(&self) -> Path<bool> {
Path::from_tokens(["status", "ready"].into_iter())
}

// ReadyConditionType returns the type of the ready condition.
pub fn ready_condition_type(&self) -> String {
"Ready".to_string()
}

// DataSecretName provide access to status.dataSecretName field in a bootstrap object.
pub fn data_secret_name(&self) -> Path<String> {
Path::from_tokens(["status", "dataSecretName"].into_iter())
}

// FailureReason provides access to the status.failureReason field in an bootstrap object. Note that this field is optional.
//
// Deprecated: This function is deprecated and is going to be removed. Please see https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more details.
pub fn failure_reason(&self) -> Path<String> {
Path::from_tokens(["status", "failureReason"].into_iter())
}

// FailureMessage provides access to the status.failureMessage field in an bootstrap object. Note that this field is optional.
//
// Deprecated: This function is deprecated and is going to be removed. Please see https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more details.
pub fn failure_message(&self) -> Path<String> {
Path::from_tokens(["status", "failureMessage"].into_iter())
}
}
44 changes: 44 additions & 0 deletions src/contract/bootstrap_config_template.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2022 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use super::{metadata::Metadata, types::Path};

// BootstrapConfigTemplateContract encodes information about the Cluster API contract for BootstrapConfigTemplate objects
// like KubeadmConfigTemplate, etc.
pub struct BootstrapConfigTemplateContract;

pub fn bootstrap_config_template() -> *const BootstrapConfigTemplateContract {
&BootstrapConfigTemplateContract
}

impl BootstrapConfigTemplateContract {
// Template provides access to the template.
pub fn template(&self) -> *const BootstrapConfigTemplateTemplate {
&BootstrapConfigTemplateTemplate
}
}

// BootstrapConfigTemplateTemplate provides a helper struct for working with the template in an BootstrapConfigTemplate.
pub struct BootstrapConfigTemplateTemplate;

impl BootstrapConfigTemplateTemplate {
// Metadata provides access to the metadata of a template.
pub fn metadata(&self) -> Metadata {
Metadata::new(Path::from_tokens(
["spec", "template", "metadata"].into_iter(),
))
}
}
Loading