Skip to content

Commit

Permalink
ClusterPool Inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
abraverm committed Feb 17, 2022
1 parent f54f0ec commit 18ac472
Show file tree
Hide file tree
Showing 36 changed files with 2,463 additions and 11 deletions.
6 changes: 6 additions & 0 deletions apis/hive/v1/clusterdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const (
// FinalizerArgoCDCluster is used on ClusterDeployments to ensure we clean up the ArgoCD cluster
// secret before cleaning up the API object.
FinalizerArgoCDCluster = "hive.openshift.io/argocd-cluster"

// FinalizerCustomizationRelease is used on ClusterDeployments to ensure we run a successful
// release of ClusterDeploymentCustomization
FinalizerCustomizationRelease string = "hive.openshift.io/customization"
)

// ClusterPowerState is used to indicate whether a cluster is running or in a
Expand Down Expand Up @@ -271,6 +275,8 @@ type ClusterPoolReference struct {
// ClaimedTimestamp is the time this cluster was assigned to a ClusterClaim. This is only used for
// ClusterDeployments belonging to ClusterPools.
ClaimedTimestamp *metav1.Time `json:"claimedTimestamp,omitempty"`
// ClusterDeploymentCustomizationRef is the ClusterPool Inventory claimed customization for this ClusterDeployment
ClusterDeploymentCustomizationRef *corev1.LocalObjectReference `json:"clusterDeploymentCustomization"`
}

// ClusterMetadata contains metadata information about the installed cluster.
Expand Down
90 changes: 90 additions & 0 deletions apis/hive/v1/clusterdeploymentcustomization_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterDeploymentCustomization is the Schema for clusterdeploymentcustomizations API
// +kubebuilder:subresource:status
// +k8s:openapi-gen=true
// +kubebuilder:resource:scope=Namespaced
type ClusterDeploymentCustomization struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ClusterDeploymentCustomizationSpec `json:"spec"`
Status ClusterDeploymentCustomizationStatus `json:"status,omitempty"`
}

// ClusterDeploymentCustomizationSpec defines the desired state of ClusterDeploymentCustomization
type ClusterDeploymentCustomizationSpec struct {
// TODO: documentation
InstallConfigPatches []PatchEntity `json:"installConfigPatches,omitempty"`
}

// TODO: documentation
type PatchEntity struct {
// +required
Op string `json:"op"`
// +required
Path string `json:"path"`
// +required
Value string `json:"value"`
}

// ClusterDeploymentCustomizationStatus defines the observed state of ClusterDeploymentCustomization
type ClusterDeploymentCustomizationStatus struct {
// TODO: documentation
// +optional
ClusterDeploymentRef *corev1.LocalObjectReference `json:"clusterDeploymentRef,omitempty"`

// Conditions includes more detailed status for the cluster deployment customization status.
// +optional
Conditions []ClusterDeploymentCustomizationCondition `json:"conditions,omitempty"`
}

type ClusterDeploymentCustomizationCondition struct {
// Type is the type of the condition.
Type ClusterDeploymentCustomizationConditionType `json:"type"`
// Status is the status of the condition.
Status corev1.ConditionStatus `json:"status"`
// LastProbeTime is the last time we probed the condition.
// +optional
LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`
// LastTransitionTime is the last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Reason is a unique, one-word, CamelCase reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// Message is a human-readable message indicating details about last transition.
// +optional
Message string `json:"message,omitempty"`
}

// ClusterDeploymentCustomizationConditionType is a valid value for ClusterDeploymentCustomizationCondition.Type
type ClusterDeploymentCustomizationConditionType string

const (
// TODO: add more types
// TODO: shorter name?
ClusterDeploymentCustomizationAvailableCondition ClusterDeploymentCustomizationConditionType = "Available"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterDeploymentCustomizationLis contains the list of ClusterDeploymentCustomization
type ClusterDeploymentCustomizationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []ClusterDeploymentCustomization `json:"items"`
}

func init() {
SchemeBuilder.Register(&ClusterDeploymentCustomization{}, &ClusterDeploymentCustomizationList{})
}
48 changes: 48 additions & 0 deletions apis/hive/v1/clusterpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ type ClusterPoolSpec struct {
// HibernationConfig configures the hibernation/resume behavior of ClusterDeployments owned by the ClusterPool.
// +optional
HibernationConfig *HibernationConfig `json:"hibernationConfig"`

// Inventory maintains a list entries consumed by the clusterpool
// to customize the default the cluster deployment
// +optional
Inventory []InventoryEntry `json:"inventory,omitempty"`

// InventoryAttempts is the number of attempts to provision a ClusterDeployment with a given inventory entry.
// On a successful provision, the inventory entry attempts status is updated to this value.
// Negative InventoryAttempts means unlimited attempts, and recommended only for debugging purposes.
// Default number of InventoryAttempts is 5.
// +optional
InventoryAttempts *int32 `json:"inventoryAttempts,omitempty"`
}

type HibernationConfig struct {
Expand All @@ -110,6 +122,22 @@ type HibernationConfig struct {
ResumeTimeout metav1.Duration `json:"resumeTimeout"`
}

// InventoryEntryKind in Kind of the inventory entry
// +kubebuilder:validation:Enum="";ClusterDeploymentCustomization
type InventoryEntryKind string

const ClusterDeploymentCustomizationInventoryEntry InventoryEntryKind = "ClusterDeploymentCustomization"

// InventoryEntry maintains a reference to a custom resource consumed by a clusterpool to customize the cluster deployment
type InventoryEntry struct {
// Kind denotes the kind of the referenced resource. The default is ClusterDeploymentCustomization, which is also currently the only supported value.
// +optional
Kind InventoryEntryKind `json:"kind,omitempty"`
// Name is the name of the referenced resource.
// +required
Name string `json:"name,omitempty"`
}

// ClusterPoolClaimLifetime defines the lifetimes for claims for the cluster pool.
type ClusterPoolClaimLifetime struct {
// Default is the default lifetime of the claim when no lifetime is set on the claim itself.
Expand Down Expand Up @@ -152,6 +180,10 @@ type ClusterPoolStatus struct {
// Conditions includes more detailed status for the cluster pool
// +optional
Conditions []ClusterPoolCondition `json:"conditions,omitempty"`

// Inventory tracks the individual status of inventory entries
// +optional
Inventory map[string]InventoryEntryStatus `json:"inventory,omitempty"`
}

// ClusterPoolCondition contains details for the current condition of a cluster pool
Expand Down Expand Up @@ -187,8 +219,24 @@ const (
// ClusterPoolAllClustersCurrentCondition indicates whether all unassigned (installing or ready)
// ClusterDeployments in the pool match the current configuration of the ClusterPool.
ClusterPoolAllClustersCurrentCondition ClusterPoolConditionType = "AllClustersCurrent"
// ClusterPoolInventoryValidCondition is set to provide information on whether the cluster pool inventory is valid
ClusterPoolInventoryValidCondition ClusterPoolConditionType = "InventoryValid"
)

// InventoryEntryStatus contains current details for the related Inventory entry
type InventoryEntryStatus struct {
// Inventory Entry Kind
Kind string `json:"kind"`
// Version of resource instance
Version string `json:"version,omitempty"`
// Status of inventory resource for the cluster pool
Status string `json:"status"`
// ClusterDeployment is a reference to ClusterDeployment using the Inventory resource
ClusterDeployment *corev1.LocalObjectReference `json:"clusterDeployment,omitempty"`
// Attempts left to try using inventory entry
Attempts int32 `json:"attempts,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
170 changes: 170 additions & 0 deletions apis/hive/v1/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 18ac472

Please sign in to comment.