Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit f5d5f20

Browse files
authored
Merge pull request #1501 from zqzten/kubernetes_version
feat: introduce Kubernetes version to status of KubeFedCluster
2 parents 96f6b8e + c56c624 commit f5d5f20

File tree

18 files changed

+119
-36
lines changed

18 files changed

+119
-36
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
- uses: actions/setup-go@v2
1313
with:
14-
go-version: '^1.16.6'
14+
go-version: '~1.16'
1515

1616
- name: Run tests
1717
run: |

.github/workflows/test-and-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
- uses: actions/setup-go@v2
1818
with:
19-
go-version: '^1.16.6'
19+
go-version: '~1.16'
2020

2121
- name: Run tests
2222
run: DOWNLOAD_BINARIES=y bash -x ./scripts/pre-commit.sh

charts/kubefed/charts/controllermanager/crds/crds.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ spec:
457457
kind: KubeFedCluster
458458
listKind: KubeFedClusterList
459459
plural: kubefedclusters
460+
shortNames:
461+
- kfc
460462
singular: kubefedcluster
461463
scope: Namespaced
462464
versions:
@@ -467,6 +469,9 @@ spec:
467469
- jsonPath: .status.conditions[?(@.type=='Ready')].status
468470
name: ready
469471
type: string
472+
- jsonPath: .status.kubernetesVersion
473+
name: kubernetes-version
474+
type: string
470475
name: v1beta1
471476
schema:
472477
openAPIV3Schema:
@@ -559,6 +564,10 @@ spec:
559564
- type
560565
type: object
561566
type: array
567+
kubernetesVersion:
568+
description: KubernetesVersion is the Kubernetes git version of the
569+
cluster.
570+
type: string
562571
region:
563572
description: Region is the name of the region in which all of the
564573
nodes in the cluster exist. e.g. 'us-east1'.

cmd/controller-manager/app/leaderelection/leaderelection.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ import (
3636

3737
func NewKubeFedLeaderElector(opts *options.Options, fnStartControllers func(*options.Options, <-chan struct{})) (*leaderelection.LeaderElector, error) {
3838
const component = "kubefed-controller-manager"
39-
restclient.AddUserAgent(opts.Config.KubeConfig, "kubefed-leader-election")
40-
leaderElectionClient := kubeclient.NewForConfigOrDie(opts.Config.KubeConfig)
39+
kubeConfig := restclient.CopyConfig(opts.Config.KubeConfig)
40+
restclient.AddUserAgent(kubeConfig, "kubefed-leader-election")
41+
leaderElectionClient := kubeclient.NewForConfigOrDie(kubeConfig)
4142

4243
hostname, err := os.Hostname()
4344
if err != nil {

docs/cluster-registration.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ Check the status of the joined clusters by using the following command.
3434
```bash
3535
kubectl -n kube-federation-system get kubefedclusters
3636

37-
NAME READY AGE
38-
cluster1 True 1m
39-
cluster2 True 1m
37+
NAME AGE READY KUBERNETES-VERSION
38+
cluster1 1m True v1.21.2
39+
cluster2 1m True v1.22.0
4040

4141
```
4242

43+
The Kubernetes version is checked periodically along with the cluster health check so that it would be automatically updated within the cluster health check period after a Kubernetes upgrade/downgrade of the cluster.
44+
4345
# Joining kind clusters on MacOS
4446

4547
A Kubernetes cluster deployed with [kind](https://sigs.k8s.io/kind) on Docker

pkg/apis/core/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/core/v1beta1/kubefedcluster_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ type LocalSecretReference struct {
7070
type KubeFedClusterStatus struct {
7171
// Conditions is an array of current cluster conditions.
7272
Conditions []ClusterCondition `json:"conditions"`
73+
// KubernetesVersion is the Kubernetes git version of the cluster.
74+
// +optional
75+
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
7376
// Zones are the names of availability zones in which the nodes of the cluster exist, e.g. 'us-east1-a'.
7477
// +optional
7578
Zones []string `json:"zones,omitempty"`
@@ -81,7 +84,8 @@ type KubeFedClusterStatus struct {
8184
// +kubebuilder:object:root=true
8285
// +kubebuilder:printcolumn:name=age,type=date,JSONPath=.metadata.creationTimestamp
8386
// +kubebuilder:printcolumn:name=ready,type=string,JSONPath=.status.conditions[?(@.type=='Ready')].status
84-
// +kubebuilder:resource:path=kubefedclusters
87+
// +kubebuilder:printcolumn:name=kubernetes-version,type=string,JSONPath=.status.kubernetesVersion
88+
// +kubebuilder:resource:path=kubefedclusters,shortName=kfc
8589
// +kubebuilder:subresource:status
8690

8791
// KubeFedCluster configures KubeFed to be aware of a Kubernetes

pkg/apis/core/v1beta1/zz_generated.deepcopy.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/scheduling/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/kubefedcluster/clusterclient.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package kubefedcluster
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"strings"
2223
"time"
2324

@@ -79,8 +80,8 @@ func NewClusterClientSet(c *fedv1b1.KubeFedCluster, client generic.Client, fedNa
7980
return &clusterClientSet, err
8081
}
8182

82-
// GetClusterHealthStatus gets the kubernetes cluster health status by requesting "/healthz"
83-
func (c *ClusterClient) GetClusterHealthStatus() (*fedv1b1.KubeFedClusterStatus, error) {
83+
// GetClusterStatus gets the kubernetes cluster's health and version status
84+
func (c *ClusterClient) GetClusterStatus() (*fedv1b1.KubeFedClusterStatus, error) {
8485
clusterStatus := fedv1b1.KubeFedClusterStatus{}
8586
currentTime := metav1.Now()
8687
clusterReady := ClusterReady
@@ -141,6 +142,8 @@ func (c *ClusterClient) GetClusterHealthStatus() (*fedv1b1.KubeFedClusterStatus,
141142
body, err := c.kubeClient.DiscoveryClient.RESTClient().Get().AbsPath("/healthz").Do(context.Background()).Raw()
142143
if err != nil {
143144
runtime.HandleError(errors.Wrapf(err, "Failed to do cluster health check for cluster %q", c.clusterName))
145+
msg := fmt.Sprintf("%s: %v", ClusterNotReachableMsg, err)
146+
newClusterOfflineCondition.Message = &msg
144147
clusterStatus.Conditions = append(clusterStatus.Conditions, newClusterOfflineCondition)
145148
metrics.RegisterKubefedClusterTotal(metrics.ClusterOffline, c.clusterName)
146149
} else {
@@ -150,6 +153,13 @@ func (c *ClusterClient) GetClusterHealthStatus() (*fedv1b1.KubeFedClusterStatus,
150153
} else {
151154
metrics.RegisterKubefedClusterTotal(metrics.ClusterReady, c.clusterName)
152155
clusterStatus.Conditions = append(clusterStatus.Conditions, newClusterReadyCondition)
156+
157+
version, err := c.kubeClient.DiscoveryClient.ServerVersion()
158+
if err != nil {
159+
runtime.HandleError(errors.Wrapf(err, "Failed to get Kubernetes version of cluster %q", c.clusterName))
160+
} else {
161+
clusterStatus.KubernetesVersion = version.GitVersion
162+
}
153163
}
154164
}
155165

0 commit comments

Comments
 (0)