Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release-3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pixiake committed Feb 22, 2024
2 parents 2d29be1 + a199259 commit f4cdca1
Show file tree
Hide file tree
Showing 32 changed files with 1,196 additions and 127 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,24 @@
"contributions": [
"code"
]
},
{
"login": "chilianyi",
"name": "chilianyi",
"avatar_url": "https://avatars.githubusercontent.com/u/5917832?v=4",
"profile": "https://github.com/chilianyi",
"contributions": [
"code"
]
},
{
"login": "xrwang8",
"name": "Ronald Fletcher",
"avatar_url": "https://avatars.githubusercontent.com/u/68765051?v=4",
"profile": "https://github.com/xrwang8",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ Contributions of any kind are welcome! Thanks goes to these wonderful contributo
<td align="center" valign="top" width="14.28%"><a href="https://dashen.tech"><img src="https://avatars.githubusercontent.com/u/15921519?v=4?s=100" width="100px;" alt="cui fliter"/><br /><sub><b>cui fliter</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=cuishuang" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/liuxu623"><img src="https://avatars.githubusercontent.com/u/9653438?v=4?s=100" width="100px;" alt="刘旭"/><br /><sub><b>刘旭</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=liuxu623" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yzxiu"><img src="https://avatars.githubusercontent.com/u/13790023?v=4?s=100" width="100px;" alt="yuyu"/><br /><sub><b>yuyu</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=yzxiu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chilianyi"><img src="https://avatars.githubusercontent.com/u/5917832?v=4?s=100" width="100px;" alt="chilianyi"/><br /><sub><b>chilianyi</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=chilianyi" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/xrwang8"><img src="https://avatars.githubusercontent.com/u/68765051?v=4?s=100" width="100px;" alt="Ronald Fletcher"/><br /><sub><b>Ronald Fletcher</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=xrwang8" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://dashen.tech"><img src="https://avatars.githubusercontent.com/u/15921519?v=4?s=100" width="100px;" alt="cui fliter"/><br /><sub><b>cui fliter</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=cuishuang" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/liuxu623"><img src="https://avatars.githubusercontent.com/u/9653438?v=4?s=100" width="100px;" alt="刘旭"/><br /><sub><b>刘旭</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=liuxu623" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yzxiu"><img src="https://avatars.githubusercontent.com/u/13790023?v=4?s=100" width="100px;" alt="yuyu"/><br /><sub><b>yuyu</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=yzxiu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chilianyi"><img src="https://avatars.githubusercontent.com/u/5917832?v=4?s=100" width="100px;" alt="chilianyi"/><br /><sub><b>chilianyi</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=chilianyi" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/xrwang8"><img src="https://avatars.githubusercontent.com/u/68765051?v=4?s=100" width="100px;" alt="Ronald Fletcher"/><br /><sub><b>Ronald Fletcher</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=xrwang8" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 4 additions & 0 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ kubectl completion bash >/etc/bash_completion.d/kubectl
<td align="center" valign="top" width="14.28%"><a href="https://dashen.tech"><img src="https://avatars.githubusercontent.com/u/15921519?v=4?s=100" width="100px;" alt="cui fliter"/><br /><sub><b>cui fliter</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=cuishuang" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/liuxu623"><img src="https://avatars.githubusercontent.com/u/9653438?v=4?s=100" width="100px;" alt="刘旭"/><br /><sub><b>刘旭</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=liuxu623" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yzxiu"><img src="https://avatars.githubusercontent.com/u/13790023?v=4?s=100" width="100px;" alt="yuyu"/><br /><sub><b>yuyu</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=yzxiu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chilianyi"><img src="https://avatars.githubusercontent.com/u/5917832?v=4?s=100" width="100px;" alt="chilianyi"/><br /><sub><b>chilianyi</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=chilianyi" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/xrwang8"><img src="https://avatars.githubusercontent.com/u/68765051?v=4?s=100" width="100px;" alt="Ronald Fletcher"/><br /><sub><b>Ronald Fletcher</b></sub></a><br /><a href="https://github.com/kubesphere/kubekey/commits?author=xrwang8" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
11 changes: 9 additions & 2 deletions cmd/kk/apis/kubekey/v1alpha2/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/util"
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/version/kubernetes"
)

const (
Expand All @@ -41,7 +42,8 @@ const (
DefaultSSHTimeout = 30
DefaultEtcdVersion = "v3.5.6"
DefaultEtcdPort = "2379"
DefaultDockerVersion = "24.0.6"
DefaultDockerVersion = "24.0.9"
DefaultCriDockerdVersion = "0.3.9"
DefaultContainerdVersion = "1.7.12"
DefaultRuncVersion = "v1.1.11"
DefaultCrictlVersion = "v1.29.0"
Expand All @@ -68,6 +70,7 @@ const (
DefaultProxyMode = "ipvs"
DefaultCrioEndpoint = "unix:///var/run/crio/crio.sock"
DefaultContainerdEndpoint = "unix:///run/containerd/containerd.sock"
DefaultCriDockerdEndpoint = "unix:///var/run/cri-dockerd.sock"
DefaultIsulaEndpoint = "unix:///var/run/isulad.sock"
Etcd = "etcd"
Master = "master"
Expand Down Expand Up @@ -315,7 +318,11 @@ func SetDefaultClusterCfg(cfg *ClusterSpec) Kubernetes {
if cfg.Kubernetes.ContainerRuntimeEndpoint == "" {
switch cfg.Kubernetes.ContainerManager {
case Docker:
cfg.Kubernetes.ContainerRuntimeEndpoint = ""
if kubernetes.IsAtLeastV124(cfg.Kubernetes.Version) {
cfg.Kubernetes.ContainerRuntimeEndpoint = DefaultCriDockerdEndpoint
} else {
cfg.Kubernetes.ContainerRuntimeEndpoint = ""
}
case Crio:
cfg.Kubernetes.ContainerRuntimeEndpoint = DefaultCrioEndpoint
case Containerd:
Expand Down
162 changes: 162 additions & 0 deletions cmd/kk/apis/kubekey/v1alpha2/multicluster_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package v1alpha2

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

type MultiClusterSpec struct {
// Join cluster as a kubefed cluster
JoinFederation bool `json:"joinFederation,omitempty"`

// Desired state of the cluster
Enable bool `json:"enable,omitempty"`

// Provider of the cluster, this field is just for description
Provider string `json:"provider,omitempty"`

// Connection holds info to connect to the member cluster
Connection Connection `json:"connection,omitempty"`

// ExternalKubeAPIEnabled export kubeapiserver to public use a lb type service if connection type is proxy
ExternalKubeAPIEnabled bool `json:"externalKubeAPIEnabled,omitempty"`
}

type ConnectionType string

const (
ConnectionTypeDirect ConnectionType = "direct"
ConnectionTypeProxy ConnectionType = "proxy"
)

type Connection struct {

// type defines how host cluster will connect to host cluster
// ConnectionTypeDirect means direct connection, this requires
// kubeconfig and kubesphere apiserver endpoint provided
// ConnectionTypeProxy means using kubesphere proxy, no kubeconfig
// or kubesphere apiserver endpoint required
Type ConnectionType `json:"type,omitempty"`

// KubeSphere API Server endpoint. Example: http://10.10.0.11:8080
// Should provide this field explicitly if connection type is direct.
// Will be populated by ks-apiserver if connection type is proxy.
KubeSphereAPIEndpoint string `json:"kubesphereAPIEndpoint,omitempty"`

// Kubernetes API Server endpoint. Example: https://10.10.0.1:6443
// Should provide this field explicitly if connection type is direct.
// Will be populated by ks-apiserver if connection type is proxy.
KubernetesAPIEndpoint string `json:"kubernetesAPIEndpoint,omitempty"`

// External Kubernetes API Server endpoint
// Will be populated by ks-apiserver if connection type is proxy and ExternalKubeAPIEnabled is true.
ExternalKubernetesAPIEndpoint string `json:"externalKubernetesAPIEndpoint,omitempty"`

// KubeConfig content used to connect to cluster api server
// Should provide this field explicitly if connection type is direct.
// Will be populated by ks-proxy if connection type is proxy.
KubeConfig []byte `json:"kubeconfig,omitempty"`

// Token used by agents of member cluster to connect to host cluster proxy.
// This field is populated by apiserver only if connection type is proxy.
Token string `json:"token,omitempty"`

// KubeAPIServerPort is the port which listens for forwarding kube-apiserver traffic
// Only applicable when connection type is proxy.
KubernetesAPIServerPort uint16 `json:"kubernetesAPIServerPort,omitempty"`

// KubeSphereAPIServerPort is the port which listens for forwarding kubesphere apigateway traffic
// Only applicable when connection type is proxy.
KubeSphereAPIServerPort uint16 `json:"kubesphereAPIServerPort,omitempty"`
}
type MultiClusterStatus struct {

// Represents the latest available observations of a cluster's current state.
Conditions []ClusterCondition `json:"conditions,omitempty"`

// GitVersion of the kubernetes cluster, this field is populated by cluster controller
KubernetesVersion string `json:"kubernetesVersion,omitempty"`

// GitVersion of the /kapis/version api response, this field is populated by cluster controller
KubeSphereVersion string `json:"kubeSphereVersion,omitempty"`

// Count of the kubernetes cluster nodes
// This field may not reflect the instant status of the cluster.
NodeCount int `json:"nodeCount,omitempty"`

// Zones are the names of availability zones in which the nodes of the cluster exist, e.g. 'us-east1-a'.
// +optional
Zones []string `json:"zones,omitempty"`

// Region is the name of the region in which all of the nodes in the cluster exist. e.g. 'us-east1'.
// +optional
Region *string `json:"region,omitempty"`

// Configz is status of components enabled in the member cluster. This is synchronized with member cluster
// every amount of time, like 5 minutes.
// +optional
Configz map[string]bool `json:"configz,omitempty"`

// UID is the kube-system namespace UID of the cluster, which represents the unique ID of the cluster.
UID types.UID `json:"uid,omitempty"`
}
type ClusterConditionType string

const (
// Cluster agent is initialized and waiting for connecting
ClusterInitialized ClusterConditionType = "Initialized"

// Cluster agent is available
ClusterAgentAvailable ClusterConditionType = "AgentAvailable"

// Cluster has been one of federated clusters
ClusterFederated ClusterConditionType = "Federated"

// Cluster external access ready
ClusterExternalAccessReady ClusterConditionType = "ExternalAccessReady"

// Cluster is all available for requests
ClusterReady ClusterConditionType = "Ready"

// Openpitrix runtime is created
ClusterOpenPitrixRuntimeReady ClusterConditionType = "OpenPitrixRuntimeReady"

// ClusterKubeConfigCertExpiresInSevenDays indicates that the cluster certificate is about to expire.
ClusterKubeConfigCertExpiresInSevenDays ClusterConditionType = "KubeConfigCertExpiresInSevenDays"
)

type ClusterCondition struct {
// Type of the condition
Type ClusterConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// The last time this condition was updated.
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
}
type MultiCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MultiClusterSpec `json:"spec,omitempty"`
Status MultiClusterStatus `json:"status,omitempty"`
}

type MultiClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MultiCluster `json:"items"`
}

const HostClusterLabel = "cluster-role.kubesphere.io/host"

func (m MultiCluster) IsHostCluster() bool {
_, host := m.Labels[HostClusterLabel]
return host
}
18 changes: 18 additions & 0 deletions cmd/kk/cmd/clusterinfo/clusterinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package clusterinfo

import (
"github.com/spf13/cobra"
)

// NewCmdClusterInfo creates a new clusterinfo command
func NewCmdClusterInfo() *cobra.Command {

cmd := &cobra.Command{
Use: "cluster-info",
Short: "display cluster information",
}

cmd.AddCommand(NewCmdClusterInfoDump())

return cmd
}
60 changes: 60 additions & 0 deletions cmd/kk/cmd/clusterinfo/clusterinfo_dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package clusterinfo

import (
"fmt"
"github.com/kubesphere/kubekey/v3/cmd/kk/cmd/util"
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/clusterinfo"
"github.com/spf13/cobra"
)

type ClusterInfoDumpOptions struct {
Options clusterinfo.DumpOption
}

func NewClusterInfoDumpOptions() *ClusterInfoDumpOptions {
return &ClusterInfoDumpOptions{}
}

func NewCmdClusterInfoDump() *cobra.Command {
o := NewClusterInfoDumpOptions()
cmd := &cobra.Command{
Use: "dump",
Short: "Dumping key cluster configurations and files",
Run: func(cmd *cobra.Command, args []string) {

util.CheckErr(o.Validate())
util.CheckErr(o.Run())

},
}

o.addFlag(cmd)
return cmd
}

func (o *ClusterInfoDumpOptions) Validate() error {
switch o.Options.Type {
case "yaml", "YAML", "json", "JSON":
default:
return fmt.Errorf("unsupport output content format [%s]", o.Options.Type)
}
return nil
}

func (o *ClusterInfoDumpOptions) addFlag(cmd *cobra.Command) {
DefaultDumpNamespaces := []string{"kubesphere-system", "kubesphere-logging-system", "kubesphere-monitoring-system", "openpitrix-system", "kube-system", "istio-system", "kubesphere-devops-system", "porter-system"}
cmd.Flags().StringArrayVar(&o.Options.Namespace, "namespaces", DefaultDumpNamespaces, "Namespaces to be dumped, separated by commas.")
cmd.Flags().StringVar(&o.Options.KubeConfig, "kube-config", "", "Path to the kube-config file")
cmd.Flags().BoolVarP(&o.Options.AllNamespaces, "all-namespaces", "A", false, "dump all namespaces.")
cmd.Flags().StringVar(&o.Options.OutputDir, "output-dir", "", "output the dump result to the specified directory directory.")
cmd.Flags().StringVarP(&o.Options.Type, "output", "o", "json", "output file content format. support in json,yaml")
cmd.Flags().BoolVarP(&o.Options.Tar, "tar", "t", false, "build the dump result into a tar")
cmd.Flags().IntVar(&o.Options.Queue, "queue", 5, "dump queue size")
cmd.Flags().BoolVar(&o.Options.Logger, "log", false, "output the dump result to the log console")
}

func (o *ClusterInfoDumpOptions) Run() error {
fmt.Println("dumping cluster info...")
return clusterinfo.Dump(o.Options)

}
3 changes: 2 additions & 1 deletion cmd/kk/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"fmt"
"github.com/kubesphere/kubekey/v3/cmd/kk/cmd/clusterinfo"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -120,7 +121,7 @@ func NewKubeKeyCommand(o KubeKeyOptions) *cobra.Command {

cmds.AddCommand(completion.NewCmdCompletion())
cmds.AddCommand(version.NewCmdVersion())

cmds.AddCommand(clusterinfo.NewCmdClusterInfo())
return cmds
}

Expand Down
Loading

0 comments on commit f4cdca1

Please sign in to comment.