Skip to content

Commit

Permalink
VPC: Extend VPC related API's for v2 VPC reconcile
Browse files Browse the repository at this point in the history
Extend the API's used in the v2 support of reconciling
VPC for the VPCCluster support.
  • Loading branch information
cjschaef committed Jul 15, 2024
1 parent 5b01057 commit 09a4350
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api/v1beta1/zz_generated.conversion.go

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

58 changes: 56 additions & 2 deletions api/v1beta2/ibmvpccluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ type VPCNetworkSpec struct {
// +optional
ResourceGroup *string `json:"resourceGroup,omitempty"`

// TODO(cjschaef): Complete spec definition (SecurityGroups, VPC)
// vpc defines the IBM Cloud VPC.
// +optional
VPC *VPCResource `json:"vpc,omitempty"`

// TODO(cjschaef): Complete spec definition (SecurityGroups, etc.)
}

// VPCSecurityGroupStatus defines a vpc security group resource status with its id and respective rule's ids.
Expand Down Expand Up @@ -146,11 +150,22 @@ type VPCLoadBalancerStatus struct {
type IBMVPCClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// dep: rely on Network instead.
VPC VPC `json:"vpc,omitempty"`

// network is the status of the VPC network resources.
// +optional
Network *VPCNetworkStatus `json:"network,omitempty"`

// Ready is true when the provider resource is ready.
// +optional
Ready bool `json:"ready"`
// +kubebuilder:default=false
Ready bool `json:"ready"`

// resourceGroup is the status of the cluster's Resource Group.
// +optional
ResourceGroup *ResourceStatus `json:"resourceGroup,omitempty"`

Subnet Subnet `json:"subnet,omitempty"`
VPCEndpoint VPCEndpoint `json:"vpcEndpoint,omitempty"`

Expand All @@ -163,6 +178,45 @@ type IBMVPCClusterStatus struct {
Conditions capiv1beta1.Conditions `json:"conditions,omitempty"`
}

// VPCNetworkStatus provides details on the status of VPC network resources.
type VPCNetworkStatus struct {
// resourceGroup references the Resource Group for Network resources for the cluster.
// This can be the same or unique from the cluster's Resource Group.
// +optional
ResourceGroup *ResourceStatus `json:"resourceGroup,omitempty"`

// vpc references the IBM Cloud VPC.
// +optional
VPC *VPCResourceStatus `json:"vpc,omitempty"`
}

// VPCResourceStatus identifies a VPC resource by id (and name) and whether it is ready.
type VPCResourceStatus struct {
// id defines the IBM Cloud ID of the resource.
// +required
ID string `json:"id"`

// name defines the name of the resource.
// +optional
Name *string `json:"name,omitempty"`

// ready defines whether the IBM Cloud VPC resource is ready.
// +required
// +kubebuilder:default=false
Ready bool `json:"ready"`
}

// Set sets the VPCResourceStatus fields.
func (s *VPCResourceStatus) Set(resource VPCResourceStatus) {
s.ID = resource.ID
// Set the name if it hasn't been, or the resource.Name won't remove it (nil).
if s.Name == nil && resource.Name != nil {
s.Name = resource.Name
}
s.Name = resource.Name
s.Ready = resource.Ready
}

// VPC holds the VPC information.
type VPC struct {
ID string `json:"id"`
Expand Down
50 changes: 50 additions & 0 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,53 @@ type VPCEndpoint struct {
// +optional
LBID *string `json:"loadBalancerIPID,omitempty"`
}

// GenericResourceReference represents a generic IBM Cloud resource.
type GenericResourceReference struct {
// id defines the generic IBM Cloud resource ID.
// +required
ID string `json:"id"`

// name defines the generic IBM Cloud resource name.
// +optional
Name *string `json:"name,omitempty"`
}

// ResourceStatus identifies a resource by id (and name) and whether it is ready.
type ResourceStatus struct {
// id defines the Id of the IBM Cloud resource status.
// +required
ID string `json:"id"`

// name defines the name of the IBM Cloud resource status.
// +optional
Name *string `json:"name,omitempty"`

// ready defines whether the IBM Cloud resource is ready.
// +required
Ready bool `json:"ready"`
}

// Set sets the ResourceStatus fields.
func (s *ResourceStatus) Set(resource ResourceStatus) {
s.ID = resource.ID
// Set the name if it hasn't been, or the incoming name won't remove it (nil).
if s.Name == nil && resource.Name != nil {
s.Name = resource.Name
}
s.Ready = resource.Ready
}

// VPCResource represents a VPC resource.
// +kubebuilder:validation:XValidation:rule="has(self.id) || has(self.name)",message="an id or name must be provided"
type VPCResource struct {
// id of the resource.
// +kubebuilder:validation:MinLength=1
// +optional
ID *string `json:"id,omitempty"`

// name of the resource.
// +kubebuilder:validation:MinLength=1
// +optional
Name *string `json:"name,omitempty"`
}
125 changes: 125 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

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

Loading

0 comments on commit 09a4350

Please sign in to comment.