-
Notifications
You must be signed in to change notification settings - Fork 362
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
Optimize k8s runtime #1600
Optimize k8s runtime #1600
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright © 2021 Alibaba Group Holding Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package registry | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"path/filepath" | ||
|
||
"github.com/sealerio/sealer/common" | ||
osi "github.com/sealerio/sealer/utils/os" | ||
"github.com/sealerio/sealer/utils/yaml" | ||
|
||
"github.com/sirupsen/logrus" | ||
"golang.org/x/crypto/bcrypt" | ||
) | ||
|
||
const ( | ||
ConfigFile = "registry.yml" | ||
SeaHub = "sea.hub" | ||
) | ||
|
||
type Config struct { | ||
IP net.IP `yaml:"ip,omitempty"` | ||
Domain string `yaml:"domain,omitempty"` | ||
Port string `yaml:"port,omitempty"` | ||
Username string `json:"username,omitempty"` | ||
Password string `json:"password,omitempty"` | ||
} | ||
|
||
func (c *Config) GenerateHtPasswd() (string, error) { | ||
if c.Username == "" || c.Password == "" { | ||
return "", fmt.Errorf("failed to generate htpasswd: registry username or passwodr is empty") | ||
} | ||
pwdHash, err := bcrypt.GenerateFromPassword([]byte(c.Password), bcrypt.DefaultCost) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to generate registry password: %v", err) | ||
} | ||
return c.Username + ":" + string(pwdHash), nil | ||
} | ||
|
||
func (c *Config) Repo() string { | ||
return fmt.Sprintf("%s:%s", c.Domain, c.Port) | ||
} | ||
|
||
func GetConfig(rootfs string, defaultRegistryIP net.IP) *Config { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaultRegistryIP => registryIP |
||
var config Config | ||
var DefaultConfig = &Config{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DefaultConfig => defaultConfig |
||
IP: defaultRegistryIP, | ||
Domain: SeaHub, | ||
Port: "5000", | ||
} | ||
registryConfigPath := filepath.Join(rootfs, common.EtcDir, ConfigFile) | ||
if !osi.IsFileExist(registryConfigPath) { | ||
logrus.Debug("use default registry config") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default registry configuration is used: \n %+v, DefaultConfig |
||
return DefaultConfig | ||
} | ||
err := yaml.UnmarshalFile(registryConfigPath, &config) | ||
if err != nil { | ||
logrus.Errorf("failed to read registry config: %v", err) | ||
return DefaultConfig | ||
} | ||
if config.IP == nil { | ||
config.IP = DefaultConfig.IP | ||
} | ||
if config.Port == "" { | ||
config.Port = DefaultConfig.Port | ||
} | ||
if config.Domain == "" { | ||
config.Domain = DefaultConfig.Domain | ||
} | ||
logrus.Debugf("show registry info, IP: %s, Domain: %s", config.IP, config.Domain) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ultimate registry configration is: |
||
return &config | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,30 @@ | |
package kubernetes | ||
|
||
const ( | ||
Cluster = "Cluster" | ||
InitConfiguration = "InitConfiguration" | ||
JoinConfiguration = "JoinConfiguration" | ||
ClusterConfiguration = "ClusterConfiguration" | ||
KubeProxyConfiguration = "KubeProxyConfiguration" | ||
KubeletConfiguration = "KubeletConfiguration" | ||
AuditPolicyYml = "audit-policy.yml" | ||
) | ||
|
||
var ( | ||
ContainerdShell = `if grep "SystemdCgroup = true" /etc/containerd/config.toml &> /dev/null; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that possible we try not to write shell in go later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, We have too many operations done by the shell,it is hard to read and maintain. this pr only move out some code section nothing to do with the logic. I plan to optimize them in the next steps. |
||
driver=systemd | ||
else | ||
driver=cgroupfs | ||
fi | ||
echo ${driver}` | ||
DockerShell = `driver=$(docker info -f "{{.CgroupDriver}}") | ||
echo "${driver}"` | ||
) | ||
|
||
// StaticFile :static file should not be template, will never be changed while initialization. | ||
type StaticFile struct { | ||
DestinationDir string | ||
Name string | ||
} | ||
|
||
//MasterStaticFiles Put static files here, can be moved to all master nodes before kubeadm execution | ||
var MasterStaticFiles = []*StaticFile{ | ||
{ | ||
DestinationDir: "/etc/kubernetes", | ||
Name: AuditPolicyYml, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passwodr => password
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ht?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this func means to gen HTTP basic authentication with username and password. so it could be rename to "GenerateHttpBasicAuth"