Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: add ServerVersion to status #5646

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/controllers/core/cluster/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type connection struct {
// but is failing a health/readiness check.
statusError string
arch string
serverVersion string
registry *container.Registry
connStatus *v1alpha1.ClusterConnectionStatus
cancelMonitor context.CancelFunc
Expand Down
72 changes: 52 additions & 20 deletions internal/controllers/core/cluster/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
conn.k8sClient = client
}
} else if obj.Spec.Connection != nil && obj.Spec.Connection.Docker != nil {
conn.connType = connectionTypeDocker
client, err := r.createDockerClient(obj.Spec.Connection.Docker)
if err != nil {
conn.initError = err.Error()
Expand All @@ -149,26 +150,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
}
}

// once cluster connection is established, try to populate arch
if conn.initError == "" && conn.arch == "" {
if conn.k8sClient != nil {
conn.arch = r.readKubernetesArch(ctx, conn.k8sClient)
} else if conn.dockerClient != nil {
conn.arch = r.readDockerArch(ctx, conn.dockerClient)
}
}

if conn.initError == "" && conn.connType == connectionTypeK8s && conn.registry == nil {
reg := conn.k8sClient.LocalRegistry(ctx)
conn.registry = &reg
}

if conn.initError == "" && conn.connType == connectionTypeK8s {
connStatus := conn.k8sClient.ConnectionConfig()
conn.connStatus = &v1alpha1.ClusterConnectionStatus{
Kubernetes: connStatus,
}
}
r.populateClusterMetadata(ctx, &conn)

r.connManager.store(nn, conn)

Expand Down Expand Up @@ -288,6 +270,55 @@ func (r *Reconciler) reportConnectionEvent(ctx context.Context, cluster *v1alpha
analytics.Get(ctx).Incr("api.cluster.connect", tags)
}

func (r *Reconciler) populateClusterMetadata(ctx context.Context, conn *connection) {
if conn.initError != "" {
return
}

switch conn.connType {
case connectionTypeK8s:
r.populateK8sMetadata(ctx, conn)
case connectionTypeDocker:
r.populateDockerMetadata(ctx, conn)
}
}

func (r *Reconciler) populateK8sMetadata(ctx context.Context, conn *connection) {
if conn.arch == "" {
conn.arch = r.readKubernetesArch(ctx, conn.k8sClient)
}

if conn.registry == nil {
reg := conn.k8sClient.LocalRegistry(ctx)
conn.registry = &reg
}

if conn.connStatus == nil {
connStatus := conn.k8sClient.ConnectionConfig()
conn.connStatus = &v1alpha1.ClusterConnectionStatus{
Kubernetes: connStatus,
}
}

if conn.serverVersion == "" {
versionInfo, err := conn.k8sClient.CheckConnected(ctx)
if err == nil {
conn.serverVersion = versionInfo.String()
}
}
}

func (r *Reconciler) populateDockerMetadata(ctx context.Context, conn *connection) {
if conn.arch == "" {
conn.arch = r.readDockerArch(ctx, conn.dockerClient)
}

if conn.serverVersion == "" {
versionInfo := conn.dockerClient.ServerVersion()
conn.serverVersion = versionInfo.Version
}
}

func (c *connection) toStatus() v1alpha1.ClusterStatus {
var connectedAt *metav1.MicroTime
if c.initError == "" && !c.createdAt.IsZero() {
Expand All @@ -313,6 +344,7 @@ func (c *connection) toStatus() v1alpha1.ClusterStatus {
return v1alpha1.ClusterStatus{
Error: clusterError,
Arch: c.arch,
Version: c.serverVersion,
ConnectedAt: connectedAt,
Registry: reg,
Connection: c.connStatus,
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/core/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ type ClusterStatus struct {
//
// +optional
Connection *ClusterConnectionStatus `json:"connection,omitempty" protobuf:"bytes,5,opt,name=connection"`

// Version is a cluster-provided, human-readable version string.
//
// +optional
Version string `json:"version,omitempty" protobuf:"bytes,6,opt,name=version"`
}

type RegistryHosting struct {
Expand Down
1,158 changes: 599 additions & 559 deletions pkg/apis/core/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pkg/apis/core/v1alpha1/generated.proto

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

7 changes: 7 additions & 0 deletions pkg/openapi/zz_generated.openapi.go

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

4 changes: 4 additions & 0 deletions pkg/webview/view.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@
"connection": {
"$ref": "#/definitions/v1alpha1ClusterConnectionStatus",
"description": "Connection status for an existing cluster.\n\n+optional"
},
"version": {
"type": "string",
"description": "Version is a cluster-provided, human-readable version string.\n\n+optional"
}
},
"title": "ClusterStatus defines the observed state of Cluster"
Expand Down
6 changes: 6 additions & 0 deletions web/src/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ declare namespace Proto {
* +optional
*/
connection?: v1alpha1ClusterConnectionStatus;
/**
* Version is a cluster-provided, human-readable version string.
*
* +optional
*/
version?: string;
}
export interface v1alpha1ClusterSpec {
/**
Expand Down