Skip to content

Commit

Permalink
ClusterPool Inventory - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
abraverm committed Feb 6, 2022
1 parent 787ae35 commit c3d165c
Show file tree
Hide file tree
Showing 31 changed files with 2,024 additions and 2 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 @@ -49,6 +49,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 @@ -266,6 +270,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{})
}
25 changes: 25 additions & 0 deletions apis/hive/v1/clusterpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ type ClusterPoolSpec struct {
// HibernationConfig configures the hibernation/resume behavior of ClusterDeployments owned by the ClusterPool.
// +optional
HibernationConfig *HibernationConfig `json:"hibernationConfig"`

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

type HibernationConfig struct {
Expand All @@ -99,6 +106,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 @@ -168,6 +191,8 @@ 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"
)

// +genclient
Expand Down
192 changes: 192 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.

1 change: 1 addition & 0 deletions cmd/hiveadmission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main() {
hivevalidatingwebhooks.NewMachinePoolValidatingAdmissionHook(decoder),
hivevalidatingwebhooks.NewSyncSetValidatingAdmissionHook(decoder),
hivevalidatingwebhooks.NewSelectorSyncSetValidatingAdmissionHook(decoder),
hivevalidatingwebhooks.NewClusterDeploymentCustomizationValidatingAdmissionHook(decoder),
)
}

Expand Down
Loading

0 comments on commit c3d165c

Please sign in to comment.