Skip to content

Commit

Permalink
derive the Default trait for all APIs
Browse files Browse the repository at this point in the history
Modify `update.sh` to generate APIs which derive the `Default` trait:

* Update the kopium command in `update.sh` so that all APIs auto-derive
  the Default trait.
* Use the enum default generator tool to generate `Default` trait impls
  for all Gateway API enums.

Signed-off-by: Sanskar Jaiswal <[email protected]>
  • Loading branch information
aryan9600 committed Apr 24, 2024
1 parent a669795 commit a77cbc0
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 187 deletions.
56 changes: 56 additions & 0 deletions src/apis/experimental/enum_defaults.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use super::httproutes::{
HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType, HTTPRouteRulesBackendRefsFiltersType,
HTTPRouteRulesBackendRefsFiltersUrlRewritePathType,
HTTPRouteRulesFiltersRequestRedirectPathType, HTTPRouteRulesFiltersType,
HTTPRouteRulesFiltersUrlRewritePathType,
};

use super::grpcroutes::{GRPCRouteRulesBackendRefsFiltersType, GRPCRouteRulesFiltersType};

impl Default for HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType {
fn default() -> Self {
HTTPRouteRulesBackendRefsFiltersRequestRedirectPathType::ReplaceFullPath
}
}

impl Default for HTTPRouteRulesBackendRefsFiltersUrlRewritePathType {
fn default() -> Self {
HTTPRouteRulesBackendRefsFiltersUrlRewritePathType::ReplaceFullPath
}
}

impl Default for GRPCRouteRulesFiltersType {
fn default() -> Self {
GRPCRouteRulesFiltersType::RequestHeaderModifier
}
}

impl Default for HTTPRouteRulesFiltersUrlRewritePathType {
fn default() -> Self {
HTTPRouteRulesFiltersUrlRewritePathType::ReplaceFullPath
}
}

impl Default for GRPCRouteRulesBackendRefsFiltersType {
fn default() -> Self {
GRPCRouteRulesBackendRefsFiltersType::RequestHeaderModifier
}
}

impl Default for HTTPRouteRulesBackendRefsFiltersType {
fn default() -> Self {
HTTPRouteRulesBackendRefsFiltersType::RequestHeaderModifier
}
}

impl Default for HTTPRouteRulesFiltersType {
fn default() -> Self {
HTTPRouteRulesFiltersType::RequestHeaderModifier
}
}

impl Default for HTTPRouteRulesFiltersRequestRedirectPathType {
fn default() -> Self {
HTTPRouteRulesFiltersRequestRedirectPathType::ReplaceFullPath
}
}
8 changes: 4 additions & 4 deletions src/apis/experimental/gatewayclasses.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -Af -
// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --docs -f -
// kopium version: 0.17.2

use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
Expand All @@ -8,7 +8,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Spec defines the desired state of GatewayClass.
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
#[kube(
group = "gateway.networking.k8s.io",
version = "v1",
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct GatewayClassSpec {
///
///
/// Support: Implementation-specific
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayClassParametersRef {
/// Group is the group of the referent.
pub group: String,
Expand All @@ -101,7 +101,7 @@ pub struct GatewayClassParametersRef {
///
/// Implementations MUST populate status on all GatewayClass resources which
/// specify their controller name.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayClassStatus {
/// Conditions is the current status from the controller for
/// this GatewayClass.
Expand Down
34 changes: 17 additions & 17 deletions src/apis/experimental/gateways.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -Af -
// kopium command: kopium --schema=derived --derive=JsonSchema --derive=Default --docs -f -
// kopium version: 0.17.2

use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
Expand All @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

/// Spec defines the desired state of Gateway.
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
#[kube(
group = "gateway.networking.k8s.io",
version = "v1",
Expand Down Expand Up @@ -209,7 +209,7 @@ pub struct GatewaySpec {
}

/// GatewayAddress describes an address that can be bound to a Gateway.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayAddresses {
/// Type of the address.
#[serde(default, skip_serializing_if = "Option::is_none", rename = "type")]
Expand All @@ -229,7 +229,7 @@ pub struct GatewayAddresses {
///
///
///
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayInfrastructure {
/// Annotations that SHOULD be applied to any resources created in response to this Gateway.
///
Expand Down Expand Up @@ -293,7 +293,7 @@ pub struct GatewayInfrastructure {
///
///
/// Support: Implementation-specific
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayInfrastructureParametersRef {
/// Group is the group of the referent.
pub group: String,
Expand All @@ -305,7 +305,7 @@ pub struct GatewayInfrastructureParametersRef {

/// Listener embodies the concept of a logical endpoint where a Gateway accepts
/// network connections.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListeners {
/// AllowedRoutes defines the types of routes that MAY be attached to a
/// Listener and the trusted namespaces where those Route resources MAY be
Expand Down Expand Up @@ -437,7 +437,7 @@ pub struct GatewayListeners {
///
///
/// Support: Core
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListenersAllowedRoutes {
/// Kinds specifies the groups and kinds of Routes that are allowed to bind
/// to this Gateway Listener. When unspecified or empty, the kinds of Routes
Expand All @@ -464,7 +464,7 @@ pub struct GatewayListenersAllowedRoutes {
}

/// RouteGroupKind indicates the group and kind of a Route resource.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListenersAllowedRoutesKinds {
/// Group is the group of the Route.
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand All @@ -478,7 +478,7 @@ pub struct GatewayListenersAllowedRoutesKinds {
///
///
/// Support: Core
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListenersAllowedRoutesNamespaces {
/// From indicates where Routes will be selected for this Gateway. Possible
/// values are:
Expand Down Expand Up @@ -521,7 +521,7 @@ pub enum GatewayListenersAllowedRoutesNamespacesFrom {
///
///
/// Support: Core
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListenersAllowedRoutesNamespacesSelector {
/// matchExpressions is a list of label selector requirements. The requirements are ANDed.
#[serde(
Expand All @@ -544,7 +544,7 @@ pub struct GatewayListenersAllowedRoutesNamespacesSelector {

/// A label selector requirement is a selector that contains values, a key, and an operator that
/// relates the key and values.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListenersAllowedRoutesNamespacesSelectorMatchExpressions {
/// key is the label key that the selector applies to.
pub key: String,
Expand Down Expand Up @@ -573,7 +573,7 @@ pub struct GatewayListenersAllowedRoutesNamespacesSelectorMatchExpressions {
///
///
/// Support: Core
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListenersTls {
/// CertificateRefs contains a series of references to Kubernetes objects that
/// contains TLS certificates and private keys. These certificates are used to
Expand Down Expand Up @@ -655,7 +655,7 @@ pub struct GatewayListenersTls {
/// References to objects with invalid Group and Kind are not valid, and must
/// be rejected by the implementation, with appropriate Conditions set
/// on the containing object.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayListenersTlsCertificateRefs {
/// Group is the group of the referent. For example, "gateway.networking.k8s.io".
/// When unspecified or empty string, core API group is inferred.
Expand Down Expand Up @@ -702,7 +702,7 @@ pub enum GatewayListenersTlsMode {
}

/// Status defines the current state of Gateway.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayStatus {
/// Addresses lists the network addresses that have been bound to the
/// Gateway.
Expand Down Expand Up @@ -743,7 +743,7 @@ pub struct GatewayStatus {
}

/// GatewayStatusAddress describes a network address that is bound to a Gateway.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayStatusAddresses {
/// Type of the address.
#[serde(default, skip_serializing_if = "Option::is_none", rename = "type")]
Expand All @@ -757,7 +757,7 @@ pub struct GatewayStatusAddresses {
}

/// ListenerStatus is the status associated with a Listener.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayStatusListeners {
/// AttachedRoutes represents the total number of Routes that have been
/// successfully attached to this Listener.
Expand Down Expand Up @@ -799,7 +799,7 @@ pub struct GatewayStatusListeners {
}

/// RouteGroupKind indicates the group and kind of a Route resource.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
pub struct GatewayStatusListenersSupportedKinds {
/// Group is the group of the Route.
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
Loading

0 comments on commit a77cbc0

Please sign in to comment.