Skip to content

Commit

Permalink
Merge pull request #1672 from abraverm/cp_onprem_pr
Browse files Browse the repository at this point in the history
ClusterPool Inventory
  • Loading branch information
openshift-merge-robot authored Aug 1, 2022
2 parents 97dd9ae + 1786bbc commit 5daa572
Show file tree
Hide file tree
Showing 65 changed files with 4,290 additions and 99 deletions.
1 change: 1 addition & 0 deletions apis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/openshift/api v0.0.0-20220531073726-6c4f186339a7
github.com/openshift/custom-resource-status v1.1.3-0.20220503160415-f2fdb4999d87
k8s.io/api v0.24.1
k8s.io/apimachinery v0.24.1
)
Expand Down
46 changes: 45 additions & 1 deletion apis/go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions apis/hive/v1/clusterdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ 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"`
// CustomizationRef is the ClusterPool Inventory claimed customization for this ClusterDeployment.
// The Customization exists in the ClusterPool namespace.
// +optional
CustomizationRef *corev1.LocalObjectReference `json:"clusterDeploymentCustomization,omitempty"`
}

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

import (
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// CustomizationApplyReasonSucceeded indicates that the customization
// worked properly on the last applied cluster deployment.
CustomizationApplyReasonSucceeded = "Succeeded"
// CustomizationApplyReasonBrokenSyntax indicates that Hive failed to apply
// customization patches on install-config. More details would be found in
// ApplySucceded condition message.
CustomizationApplyReasonBrokenSyntax = "BrokenBySyntax"
// CustomizationApplyReasonBrokenCloud indicates that cluster deployment provision has failed
// when using this customization. More details would be found in the ApplySucceeded condition message.
CustomizationApplyReasonBrokenCloud = "BrokenByCloud"
// CustomizationApplyReasonInstallationPending indicates that the customization patches have
// been successfully applied but provisioning is not completed yet.
CustomizationApplyReasonInstallationPending = "InstallationPending"
)

// +genclient
// +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 {
// InstallConfigPatches is a list of patches to be applied to the install-config.
InstallConfigPatches []PatchEntity `json:"installConfigPatches,omitempty"`
}

// PatchEntity represent a json patch (RFC 6902) to be applied to the install-config
type PatchEntity struct {
// Op is the operation to perform: add, remove, replace, move, copy, test
// +required
Op string `json:"op"`
// Path is the json path to the value to be modified
// +required
Path string `json:"path"`
// From is the json path to copy or move the value from
// +optional
From string `json:"from,omitempty"`
// Value is the value to be used in the operation
// +required
Value string `json:"value"`
}

// ClusterDeploymentCustomizationStatus defines the observed state of ClusterDeploymentCustomization.
type ClusterDeploymentCustomizationStatus struct {
// ClusterDeploymentRef is a reference to the cluster deployment that this customization is applied on.
// +optional
ClusterDeploymentRef *corev1.LocalObjectReference `json:"clusterDeploymentRef,omitempty"`

// ClusterPoolRef is the name of the current cluster pool the CDC used at.
// +optional
ClusterPoolRef *corev1.LocalObjectReference `json:"clusterPoolRef,omitempty"`

// LastAppliedConfiguration contains the last applied patches to the install-config.
// The information will retain for reference in case the customization is updated.
// +optional
LastAppliedConfiguration string `json:"lastAppliedConfiguration,omitempty"`

// Conditions describes the state of the operator's reconciliation functionality.
// +patchMergeKey=type
// +patchStrategy=merge
// +optional
Conditions []conditionsv1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

const (
ApplySucceededCondition conditionsv1.ConditionType = "ApplySucceeded"
)

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

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

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

// Inventory maintains a list of entries consumed by the ClusterPool
// to customize the default ClusterDeployment.
// +optional
Inventory []InventoryEntry `json:"inventory,omitempty"`
}

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

// InventoryEntryKind is the 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.
// +kubebuilder:default=ClusterDeploymentCustomization
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 @@ -197,6 +218,17 @@ 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"
)

const (
// InventoryReasonValid is used when all ClusterDeploymentCustomization are
// available and when used the ClusterDeployments are successfully installed.
InventoryReasonValid = "Valid"
// InventoryReasonInvalid is used when there is something wrong with ClusterDeploymentCustomization, for example
// patching issue, provisioning failure, missing, etc.
InventoryReasonInvalid = "Invalid"
)

// +genclient
Expand Down
158 changes: 158 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 5daa572

Please sign in to comment.