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

feat: support ha mode for local registry #1901

Merged
merged 2 commits into from
Dec 15, 2022

Conversation

kakaZhou719
Copy link
Member

@kakaZhou719 kakaZhou719 commented Dec 2, 2022

Describe what this PR does / why we need it

Master0 plays an important role in sealer cluster, it hosts many important components such as sealer builtin registry,
application images launched history and others cluster configuration files. if the master0 node is abnormal, a highly
available solution is required to recover on other master nodes.

Does this pull request fix one issue?

Describe how you did it

  1. expose Registry struct to clusterfile which is contains configurations about local registry and remote registry.
  2. sync all registry configuration and registry data to the registry deploy hosts when init the cluster.
  3. set ha mode as default value for local registry.
  4. bugfix: reset host alias about cluster api server to master's their own IP, after join the new master role.
  5. optimized some flags of the sealer cluster command.

Describe how to verify it

if not set any registry configs, sealer will use non ha mode as default.
if set: below is my test clusterfile, this will prepare to deploy registry service on three nodes(172.16.26.162,172.16.26.163,172.16.26.164) with customized domain port, basic auth and insure mode options.

apiVersion: sealer.cloud/v2
kind: Cluster
metadata:
  creationTimestamp: null
  name: my-cluster
spec:
  hosts:
  - ips:
    - 172.16.26.162
    roles:
    - master
    ssh: {}
  - ips:
    - 172.16.26.163
    roles:
    - master
    ssh: {}
  - ips:
    - 172.16.26.164
    roles:
    - master
    ssh: {}
  - ips:
    - 172.16.26.165
    roles:
    - node
    ssh: {}
  registry: 
    localRegistry:
      haMode: true
      domain: kakazhou
      port: 5000 
      username: kakazhou
      password: kakazhou123
  image: registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.22.15
  ssh:
    passwd: XXX
    pk: /root/.ssh/id_rsa
    port: "22"
    user: root

Special notes for reviews

@luckyfengyong
Copy link

Please make sure it won't break backward compatibility and upgrade

cmd/sealer/cmd/cluster/apply.go Outdated Show resolved Hide resolved
pkg/infradriver/ssh_infradriver.go Outdated Show resolved Hide resolved
@kakaZhou719 kakaZhou719 changed the title feat: support recover master0 feat: support ha mode for local registry Dec 12, 2022
@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2022

Codecov Report

Base: 21.11% // Head: 21.70% // Increases project coverage by +0.58% 🎉

Coverage data is based on head (e7fbae0) compared to base (fbd817f).
Patch coverage: 24.73% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1901      +/-   ##
==========================================
+ Coverage   21.11%   21.70%   +0.58%     
==========================================
  Files          74       78       +4     
  Lines        6762     7155     +393     
==========================================
+ Hits         1428     1553     +125     
- Misses       5148     5395     +247     
- Partials      186      207      +21     
Impacted Files Coverage Δ
build/kubefile/parser/kubefile.go 53.44% <0.00%> (-1.91%) ⬇️
pkg/cluster-runtime/apps.go 0.00% <0.00%> (ø)
pkg/cluster-runtime/hook.go 3.75% <0.00%> (-0.05%) ⬇️
pkg/cluster-runtime/installer.go 0.00% <0.00%> (ø)
pkg/cluster-runtime/scale.go 0.00% <0.00%> (ø)
pkg/cluster-runtime/uninstall.go 0.00% <0.00%> (ø)
pkg/image/reference/util.go 83.78% <ø> (ø)
pkg/imagedistributor/scp_distributor.go 0.00% <0.00%> (ø)
pkg/logger/formatter.go 81.13% <ø> (ø)
pkg/runtime/kubernetes/kubeadm/kubeadm_config.go 15.51% <0.00%> (-0.28%) ⬇️
... and 19 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -99,17 +95,17 @@ func NewApplyCmd() *cobra.Command {

if extension.Type == v12.AppInstaller {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about extract a public method to determine if it is an app image?


logrus.Infof("start to apply with mode(%s)", common.ApplyModeLoadImage)
deployHosts := infraDriver.GetHostIPListByRole(common.MASTER)
master0 := deployHosts[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will panic here if the length of deploy hosts is zero

}
if _, ok := node.Labels["node-role.kubernetes.io/master"]; ok {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use MasterRoleLabel here

}

func getNodeAddress(node corev1.Node) net.IP {
if len(node.Status.Addresses) < 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if len(node.Status.Addresses)==1?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment here if the logic is right

}

func installApplication(appImageName string, launchCmds []string, extension v12.ImageExtension,
infraDriver infradriver.InfraDriver, imageEngine imageengine.Interface) error {
infraDriver infradriver.InfraDriver, imageEngine imageengine.Interface, createMode string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

installMode ?

DeployHost: infraDriver.GetHostIPListByRole(common.MASTER)[0],
Registry: config,
if createMode == common.ApplyModeLoadImage {
return loadImageMode(infraDriver, distributor)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadImageMode

the function name should be a verb

@@ -148,10 +152,9 @@ func NewRunCmd() *cobra.Command {
return runCmd
}

func createNewCluster(clusterImageName string, infraDriver infradriver.InfraDriver, imageEngine imageengine.Interface, cf clusterfile.Interface) error {
func createNewCluster(clusterImageName string, infraDriver infradriver.InfraDriver, imageEngine imageengine.Interface, cf clusterfile.Interface, createMode string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the clusterImageName is unused

func loadImageMode(infraDriver infradriver.InfraDriver, distributor imagedistributor.Distributor) error {
regConfig := infraDriver.GetClusterRegistryConfig()
// only support load image to local registry at present
if regConfig.LocalRegistry == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add TODO here

@@ -17,6 +17,8 @@ package infradriver
import (
"net"

v2 "github.com/sealerio/sealer/types/api/v2"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused blank

if err := checkAllHostsSameFamily(ret.hosts); err != nil {
// check registry config is valid,
// make sure external registry domain is valid
if cluster.Spec.Registry.ExternalRegistry != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future, we should not distinguish the local registry and external registry

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add TODO here

@starnop
Copy link
Collaborator

starnop commented Dec 12, 2022

set non-ha mode as the default value for the local registry if we support config it, and then we will make sure it won't break backward compatibility and upgrade

@@ -189,7 +189,9 @@ func NewKubeadmConfig(fromClusterFile KubeadmConfig, fromFile string,
conf.APIServer.ExtraArgs[EtcdServers] = getEtcdEndpointsWithHTTPSPrefix(masters)
conf.IPVS.ExcludeCIDRs = append(conf.KubeProxyConfiguration.IPVS.ExcludeCIDRs, fmt.Sprintf("%s/32", apiServerVIP))
conf.KubeletConfiguration.CgroupDriver = cgroupDriver

// set cluster image repo,kubeadm will pull container image from this registry.
conf.ClusterConfiguration.ImageRepository = imageRepo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VinceCui , here will affects the configuration of the ackd image. pls review.

types/api/v2/cluster_types.go Outdated Show resolved Hide resolved
pkg/infradriver/ssh_infradriver.go Outdated Show resolved Hide resolved
@@ -326,7 +249,7 @@ func (c *localSingletonConfigurator) configureAccessCredential(hosts []net.IP) e
return nil
}

func (c *localSingletonConfigurator) copy2RemoteHosts(src, dest string, hosts []net.IP) error {
func (c *localConfigurator) copy2RemoteHosts(src, dest string, hosts []net.IP) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this maybe a common func of infraDriver.

}
}

type localInstaller struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localInstaller and local registry configurator, difference? why need them both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installer provide registry lifecycle management local registry will implement it. Configurator provide registry configuration management, local registry and external registry will implement it.

// if LocalRegistry is not specified, default value is true.
HaMode bool `json:"ha_mode,omitempty"`
// InsecureMode indicated that whether the local registry is exposed in HTTPS.
// if true sealer will generate default ssl cert.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if true, sealer will NOT generate default ssl cert.

@kakaZhou719 kakaZhou719 force-pushed the feat-recover-master0 branch 3 times, most recently from fe86cf7 to bfbfaf3 Compare December 13, 2022 11:03
update reviews

update reviews
@VinceCui
Copy link
Collaborator

LGTM

@starnop
Copy link
Collaborator

starnop commented Dec 15, 2022

LGTM

@starnop starnop merged commit ce6e62a into sealerio:main Dec 15, 2022
jsparter pushed a commit to jsparter/sealer that referenced this pull request Dec 16, 2022
* feat: support recover master0

* feat: support ha mode for local registry

update reviews

update reviews
@kakaZhou719 kakaZhou719 deleted the feat-recover-master0 branch March 8, 2023 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants