Skip to content

Commit

Permalink
feat(core): kubeconfig registry controller (#526)
Browse files Browse the repository at this point in the history
* update ClusterKubeconfig resource: add status

* add kubeconfig controller

* Automatic generation of CRD API Docs

* add kubeonfig_controller tests

* Automatic generation of CRD API Docs

* Update pkg/controllers/cluster/kubeconfig_controller.go

Co-authored-by: IvoGoman <[email protected]>

* Update pkg/controllers/cluster/suite_test.go

Co-authored-by: IvoGoman <[email protected]>

* skip reconcile when cluster is not found

* fix: skip reconcile when cluster is not found

* move oidc data up, fail early

* Automatic generation of CRD API Docs

* start using CreateOrPatch

* CreateOrPatch changes

* update with one CreateOrPatch

* Update pkg/controllers/cluster/kubeconfig_controller.go

Co-authored-by: Uwe Mayer <[email protected]>

* status subresource and conditions

* Automatic generation of CRD API Docs

* fix linter

* fix org cannot be deleted

* feat: add predicate to enqueue only for ready clusters

* Automatic generation of CRD API Docs

* fix check for cluster ready

* simplify condition

* Automatic generation of CRD API Docs

---------

Co-authored-by: CRD API Docs Bot <[email protected]>
Co-authored-by: IvoGoman <[email protected]>
Co-authored-by: Uwe Mayer <[email protected]>
  • Loading branch information
4 people authored Oct 15, 2024
1 parent c139e30 commit 75babf1
Show file tree
Hide file tree
Showing 13 changed files with 733 additions and 11 deletions.
47 changes: 44 additions & 3 deletions charts/manager/crds/greenhouse.sap_clusterkubeconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,52 @@ spec:
- name
type: object
type: array
required:
- contexts
- users
type: object
type: object
status:
properties:
statusConditions:
description: |-
A StatusConditions contains a list of conditions.
Only one condition of a given type may exist in the list.
properties:
conditions:
items:
description: Condition contains additional information on the
state of a resource.
properties:
lastTransitionTime:
description: LastTransitionTime is the last time the condition
transitioned from one status to another.
format: date-time
type: string
message:
description: Message is an optional human readable message
indicating details about the last transition.
type: string
reason:
description: Reason is a one-word, CamelCase reason for
the condition's last transition.
type: string
status:
description: Status of the condition.
type: string
type:
description: Type of the condition.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
type: object
type: object
type: object
served: true
storage: true
subresources:
status: {}
11 changes: 11 additions & 0 deletions charts/manager/templates/manager-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ rules:
- patch
- update
- watch
- apiGroups:
- greenhouse.sap
resources:
- cluster-kubeconfigs
verbs:
- create
- get
- list
- patch
- update
- watch
- apiGroups:
- greenhouse.sap
resources:
Expand Down
1 change: 1 addition & 0 deletions cmd/greenhouse/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var knownControllers = map[string]func(controllerName string, mgr ctrl.Manager)
"clusterDirectAccess": startClusterDirectAccessReconciler,
// "clusterPropagation": (&clustercontrollers.ClusterPropagationReconciler{}).SetupWithManager,
"clusterStatus": (&clustercontrollers.ClusterStatusReconciler{}).SetupWithManager,
"kubeconfig": (&clustercontrollers.KubeconfigReconciler{}).SetupWithManager,
}

// knownControllers lists the name of known controllers.
Expand Down
45 changes: 45 additions & 0 deletions docs/reference/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ <h3 id="greenhouse.sap/v1alpha1.ClusterKubeconfig">ClusterKubeconfig
</table>
</td>
</tr>
<tr>
<td>
<code>status</code><br>
<em>
<a href="#greenhouse.sap/v1alpha1.ClusterKubeconfigStatus">
ClusterKubeconfigStatus
</a>
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -610,6 +622,38 @@ <h3 id="greenhouse.sap/v1alpha1.ClusterKubeconfigSpec">ClusterKubeconfigSpec
</table>
</div>
</div>
<h3 id="greenhouse.sap/v1alpha1.ClusterKubeconfigStatus">ClusterKubeconfigStatus
</h3>
<p>
(<em>Appears on:</em>
<a href="#greenhouse.sap/v1alpha1.ClusterKubeconfig">ClusterKubeconfig</a>)
</p>
<div class="md-typeset__scrollwrap">
<div class="md-typeset__table">
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>statusConditions</code><br>
<em>
<a href="#greenhouse.sap/v1alpha1.StatusConditions">
StatusConditions
</a>
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 id="greenhouse.sap/v1alpha1.ClusterOptionOverride">ClusterOptionOverride
</h3>
<p>
Expand Down Expand Up @@ -2486,6 +2530,7 @@ <h3 id="greenhouse.sap/v1alpha1.StatusConditions">StatusConditions
</h3>
<p>
(<em>Appears on:</em>
<a href="#greenhouse.sap/v1alpha1.ClusterKubeconfigStatus">ClusterKubeconfigStatus</a>,
<a href="#greenhouse.sap/v1alpha1.ClusterStatus">ClusterStatus</a>,
<a href="#greenhouse.sap/v1alpha1.NodeStatus">NodeStatus</a>,
<a href="#greenhouse.sap/v1alpha1.PluginPresetStatus">PluginPresetStatus</a>,
Expand Down
41 changes: 37 additions & 4 deletions docs/reference/api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Greenhouse
version: ba473e9
version: bd165f9
description: PlusOne operations platform
paths:
/TeamMembership:
Expand Down Expand Up @@ -860,9 +860,42 @@ components:
- name
type: object
type: array
required:
- contexts
- users
type: object
type: object
status:
properties:
statusConditions:
description: A StatusConditions contains a list of conditions.\nOnly one condition of a given type may exist in the list.
properties:
conditions:
items:
description: Condition contains additional information on the state of a resource.
properties:
lastTransitionTime:
description: LastTransitionTime is the last time the condition transitioned from one status to another.
format: date-time
type: string
message:
description: Message is an optional human readable message indicating details about the last transition.
type: string
reason:
description: Reason is a one-word, CamelCase reason for the condition's last transition.
type: string
status:
description: Status of the condition.
type: string
type:
description: Type of the condition.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
type: object
type: object
type: object
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cloudoperators/greenhouse

go 1.23
go 1.23.0

replace (
// DEX import matches version v2.41.1.
Expand Down
19 changes: 16 additions & 3 deletions pkg/apis/greenhouse/v1alpha1/clusterkubeconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type ClusterKubeconfigData struct {
Kind string `json:"kind,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Clusters []ClusterKubeconfigClusterItem `json:"clusters,omitempty"`
AuthInfo []ClusterKubeconfigAuthInfoItem `json:"users"`
Contexts []ClusterKubeconfigContextItem `json:"contexts"`
AuthInfo []ClusterKubeconfigAuthInfoItem `json:"users,omitempty"`
Contexts []ClusterKubeconfigContextItem `json:"contexts,omitempty"`
CurrentContext string `json:"current-context,omitempty"`
Preferences ClusterKubeconfigPreferences `json:"preferences,omitempty"`
}
Expand Down Expand Up @@ -63,6 +63,7 @@ type ClusterKubeconfigPreferences struct {
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=cluster-kubeconfig;cluster-kubeconfigs

// ClusterKubeconfig is the Schema for the clusterkubeconfigs API
Expand All @@ -73,9 +74,21 @@ type ClusterKubeconfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ClusterKubeconfigSpec `json:"spec,omitempty"`
Spec ClusterKubeconfigSpec `json:"spec,omitempty"`
Status ClusterKubeconfigStatus `json:"status,omitempty"`
}

// +kubebuilder:object:generate=true
type ClusterKubeconfigStatus struct {
Conditions StatusConditions `json:"statusConditions,omitempty"`
}

const (
KubeconfigCreatedCondition ConditionType = "Created"
KubeconfigReconcileFailedCondition ConditionType = "ReconcileFailed"
KubeconfigReadyCondition ConditionType = "Ready"
)

//+kubebuilder:object:root=true

// ClusterKubeconfigList contains a list of ClusterKubeconfig
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/greenhouse/v1alpha1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions pkg/clientutil/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ func PredicateClusterByAccessMode(accessMode greenhousev1alpha1.ClusterAccessMod
})
}

func PredicateClusterIsReady() predicate.Predicate {
return predicate.NewPredicateFuncs(func(o client.Object) bool {
cluster, ok := o.(*greenhousev1alpha1.Cluster)
if !ok {
return false
}
return cluster.Status.IsReadyTrue()
})
}

func PredicateByName(name string) predicate.Predicate {
return predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == name
Expand Down
Loading

0 comments on commit 75babf1

Please sign in to comment.