Skip to content

Commit

Permalink
feat: v0.5.0.dev231215 (#198)
Browse files Browse the repository at this point in the history
* repo-sync-2023-12-15T17:04:07+0800

* repo-sync-2023-12-15T17:47:55+0800
  • Loading branch information
CodePorterL authored Dec 15, 2023
1 parent afbd526 commit c4b58da
Show file tree
Hide file tree
Showing 134 changed files with 11,493 additions and 617 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`Fixed` for any bug fixes.
`Security` in case of vulnerabilities.

## [0.5.0.dev231215] - 2023-12-15
### Added
- Add document for deploying Kuscia on k8s.
### Changed
- Optimize log output.

## [0.5.0.dev231205] - 2023-12-5
### Changed
- Optimize Kuscia deployment configuration and add configuration documentation.
Expand Down
7 changes: 2 additions & 5 deletions cmd/kuscia/autonomy/autonomy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ func Run(ctx context.Context, configFile string, onlyControllers bool) error {
defer cancel()

kusciaConf := confloader.ReadConfig(configFile, common.RunModeAutonomy)
nlog.Debugf("Read kuscia config: %+v", kusciaConf)
conf := modules.InitDependencies(ctx, kusciaConf)
defer conf.Close()

// dns must start before dependencies because that dependencies init process may access network.
var coreDnsModule modules.Module
if !onlyControllers {
coreDnsModule = modules.RunCoreDNS(runCtx, cancel, &kusciaConf)
}

conf := modules.InitDependencies(ctx, kusciaConf, onlyControllers)
defer conf.Close()

if onlyControllers {
conf.MakeClients()
modules.RunOperatorsAllinOne(runCtx, cancel, conf, true)
Expand Down
13 changes: 4 additions & 9 deletions cmd/kuscia/confloader/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ import (
var (
defaultRootDir = "/home/kuscia/"
defaultEndpointForMaster = "https://127.0.0.1:6443"
CertPrefix = "etc/certs/"
LogPrefix = "var/logs/"
StdoutPrefix = "var/stdout/"
TmpPrefix = "var/tmp/"
ConfPrefix = "etc/conf/"
)

type KusciaConfig struct {
Expand Down Expand Up @@ -129,10 +124,10 @@ func defaultKusciaConfig(rootDir string) KusciaConfig {
}
return KusciaConfig{
RootDir: rootDir,
CAKeyFile: filepath.Join(rootDir, TmpPrefix, "ca.key"),
CACertFile: filepath.Join(rootDir, TmpPrefix, "ca.crt"),
DomainKeyFile: filepath.Join(rootDir, TmpPrefix, "domain.key"),
DomainCertFile: filepath.Join(rootDir, TmpPrefix, "domain.crt"),
CAKeyFile: filepath.Join(rootDir, common.CertPrefix, "ca.key"),
CACertFile: filepath.Join(rootDir, common.CertPrefix, "ca.crt"),
DomainKeyFile: filepath.Join(rootDir, common.CertPrefix, "domain.key"),
DomainCertFile: filepath.Join(rootDir, common.CertPrefix, "domain.crt"),
EnvoyIP: hostIP,
KusciaAPI: kaconfig.NewDefaultKusciaAPIConfig(rootDir),
}
Expand Down
1 change: 0 additions & 1 deletion cmd/kuscia/confloader/secretbackendloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/secretflow/kuscia/pkg/secretbackend"
// register driver
_ "github.com/secretflow/kuscia/pkg/secretbackend/mem"
_ "github.com/secretflow/kuscia/pkg/secretbackend/rfile"
)

type SecretBackendParams struct {
Expand Down
8 changes: 2 additions & 6 deletions cmd/kuscia/lite/lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/secretflow/kuscia/cmd/kuscia/modules"
"github.com/secretflow/kuscia/cmd/kuscia/utils"
"github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/utils/nlog"
)

func NewLiteCommand(ctx context.Context) *cobra.Command {
Expand All @@ -48,14 +47,11 @@ func Run(ctx context.Context, configFile string) error {
runCtx, cancel := context.WithCancel(ctx)
defer cancel()
kusciaConf := confloader.ReadConfig(configFile, common.RunModeLite)
nlog.Debugf("Read kuscia config: %+v", kusciaConf)
conf := modules.InitDependencies(ctx, kusciaConf)
defer conf.Close()

// dns must start before dependencies because that dependencies init process may access network.
coreDnsModule := modules.RunCoreDNS(runCtx, cancel, &kusciaConf)

conf := modules.InitDependencies(ctx, kusciaConf, false)
defer conf.Close()

conf.MakeClients()

if conf.EnableContainerd {
Expand Down
6 changes: 2 additions & 4 deletions cmd/kuscia/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ func Run(ctx context.Context, configFile string, onlyControllers bool) error {
defer cancel()

kusciaConf := confloader.ReadConfig(configFile, common.RunModeMaster)
nlog.Debugf("Read kuscia config: %+v", kusciaConf)
conf := modules.InitDependencies(ctx, kusciaConf)
defer conf.Close()

// dns must start before dependencies because that dependencies init process may access network.
var coreDnsModule modules.Module
if !onlyControllers {
coreDnsModule = modules.RunCoreDNS(runCtx, cancel, &kusciaConf)
}

conf := modules.InitDependencies(ctx, kusciaConf, onlyControllers)

if onlyControllers {
conf.MakeClients()
modules.RunOperatorsAllinOne(runCtx, cancel, conf, false)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kuscia/modules/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"path/filepath"
"time"

"github.com/secretflow/kuscia/cmd/kuscia/confloader"
"github.com/secretflow/kuscia/pkg/agent/commands"
"github.com/secretflow/kuscia/pkg/agent/config"
"github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/utils/kubeconfig"
"github.com/secretflow/kuscia/pkg/utils/meta"
"github.com/secretflow/kuscia/pkg/utils/nlog"
Expand All @@ -47,7 +47,7 @@ func NewAgent(i *Dependencies) Module {
if err != nil {
nlog.Fatalf("Get hostname fail: %v", err)
}
conf.StdoutPath = filepath.Join(i.RootDir, confloader.StdoutPrefix)
conf.StdoutPath = filepath.Join(i.RootDir, common.StdoutPrefix)
if conf.Node.NodeName == "" {
conf.Node.NodeName = hostname
}
Expand Down
1 change: 1 addition & 0 deletions cmd/kuscia/modules/allinone_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func RunOperatorsAllinOne(runctx context.Context, cancel context.CancelFunc, con

if startAgent {
RunAgent(runctx, cancel, conf)
RunConfManager(runctx, cancel, conf)
RunDataMesh(runctx, cancel, conf)
RunTransport(runctx, cancel, conf)
}
Expand Down
14 changes: 12 additions & 2 deletions cmd/kuscia/modules/confmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"encoding/json"
"fmt"
"io"
"sync/atomic"
"time"

"github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/confmanager/commands"
"github.com/secretflow/kuscia/pkg/confmanager/config"
"github.com/secretflow/kuscia/pkg/confmanager/service"
Expand Down Expand Up @@ -77,14 +79,20 @@ func NewConfManager(ctx context.Context, d *Dependencies) (Module, error) {
conf.DomainKey = d.DomainKey
conf.TLS.RootCA = d.CACert
conf.TLS.RootCAKey = d.CAKey
conf.DomainCertValue = &d.DomainCertByMasterValue
switch d.RunMode {
case common.RunModeLite:
conf.DomainCertValue = &d.DomainCertByMasterValue
case common.RunModeAutonomy:
conf.DomainCertValue = &atomic.Value{}
conf.DomainCertValue.Store(d.DomainCert)
}
secretBackend := findSecretBackend(d.SecretBackendHolder, conf.Backend)
if secretBackend == nil {
return nil, fmt.Errorf("failed to find secret backend %s for cm", conf.Backend)
}
conf.BackendDriver = secretBackend

nlog.Infof("Conf manager config is %+v", conf)
nlog.Debugf("Conf manager config is %+v", conf)

if err := conf.TLS.GenerateServerKeyCerts(serverCertsCommonName, nil, []string{defaultServerCertsSanDNSName}); err != nil {
return nil, err
Expand All @@ -110,7 +118,9 @@ func (m confManagerModule) Run(ctx context.Context) error {

func (m confManagerModule) WaitReady(ctx context.Context) error {
timeoutTicker := time.NewTicker(30 * time.Second)
defer timeoutTicker.Stop()
checkTicker := time.NewTicker(1 * time.Second)
defer checkTicker.Stop()
for {
select {
case <-checkTicker.C:
Expand Down
10 changes: 5 additions & 5 deletions cmd/kuscia/modules/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"path/filepath"
"time"

"github.com/secretflow/kuscia/cmd/kuscia/confloader"
pkgcom "github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/utils/common"
"github.com/secretflow/kuscia/pkg/utils/nlog"
"github.com/secretflow/kuscia/pkg/utils/nlog/ljwriter"
Expand All @@ -44,8 +44,8 @@ func NewContainerd(i *Dependencies) Module {
}

func (s *containerdModule) Run(ctx context.Context) error {
configPath := filepath.Join(s.Root, confloader.ConfPrefix, "containerd.toml")
configPathTmpl := filepath.Join(s.Root, confloader.ConfPrefix, "containerd.toml.tmpl")
configPath := filepath.Join(s.Root, pkgcom.ConfPrefix, "containerd.toml")
configPathTmpl := filepath.Join(s.Root, pkgcom.ConfPrefix, "containerd.toml.tmpl")
if err := common.RenderConfig(configPathTmpl, configPath, s); err != nil {
return err
}
Expand All @@ -54,7 +54,7 @@ func (s *containerdModule) Run(ctx context.Context) error {
crictlFile := "/etc/crictl.yaml"
if _, err := os.Stat(crictlFile); err != nil {
if os.IsNotExist(err) {
if err = os.Link(filepath.Join(s.Root, confloader.ConfPrefix, "crictl.yaml"), crictlFile); err != nil {
if err = os.Link(filepath.Join(s.Root, pkgcom.ConfPrefix, "crictl.yaml"), crictlFile); err != nil {
return err
}
} else {
Expand All @@ -72,7 +72,7 @@ func (s *containerdModule) Run(ctx context.Context) error {
}

sp := supervisor.NewSupervisor("containerd", nil, -1)
s.LogConfig.LogPath = filepath.Join(s.Root, confloader.LogPrefix, "containerd.log")
s.LogConfig.LogPath = filepath.Join(s.Root, pkgcom.LogPrefix, "containerd.log")
lj, _ := ljwriter.New(&s.LogConfig)
n := nlog.NewNLog(nlog.SetWriter(lj))
return sp.Run(ctx, func(ctx context.Context) supervisor.Cmd {
Expand Down
5 changes: 3 additions & 2 deletions cmd/kuscia/modules/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/client-go/kubernetes"

"github.com/secretflow/kuscia/cmd/kuscia/confloader"
"github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/coredns"
"github.com/secretflow/kuscia/pkg/utils/network"
"github.com/secretflow/kuscia/pkg/utils/nlog"
Expand Down Expand Up @@ -120,7 +121,7 @@ func (s *CorednsModule) Run(ctx context.Context) error {
)
dnsserver.Directives = directives

contents, err := os.ReadFile(filepath.Join(s.rootDir, confloader.ConfPrefix, "corefile"))
contents, err := os.ReadFile(filepath.Join(s.rootDir, common.ConfPrefix, "corefile"))
if err != nil {
return err
}
Expand Down Expand Up @@ -183,7 +184,7 @@ func prepareResolvConf(rootDir string) error {
}

resolvConf := "/etc/resolv.conf"
backupResolvConf := filepath.Join(rootDir, confloader.TmpPrefix, "resolv.conf")
backupResolvConf := filepath.Join(rootDir, common.TmpPrefix, "resolv.conf")
exist := paths.CheckFileExist(backupResolvConf)
if !exist {
if err = paths.CopyFile(resolvConf, backupResolvConf); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/kuscia/modules/domainroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"path/filepath"
"time"

"github.com/secretflow/kuscia/cmd/kuscia/confloader"
"github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/gateway/commands"
"github.com/secretflow/kuscia/pkg/gateway/config"
Expand All @@ -42,7 +41,7 @@ type domainRouteModule struct {
func NewDomainRoute(i *Dependencies) Module {
conf := config.DefaultStaticGatewayConfig()
conf.RootDir = i.RootDir
conf.ConfBasedir = filepath.Join(i.RootDir, confloader.ConfPrefix, "domainroute")
conf.ConfBasedir = filepath.Join(i.RootDir, common.ConfPrefix, "domainroute")
conf.DomainID = i.DomainID
conf.DomainKey = i.DomainKey
conf.MasterConfig = &i.Master
Expand Down
12 changes: 6 additions & 6 deletions cmd/kuscia/modules/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"gopkg.in/yaml.v3"

"github.com/secretflow/kuscia/cmd/kuscia/confloader"
"github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/gateway/utils"
"github.com/secretflow/kuscia/pkg/utils/nlog"
"github.com/secretflow/kuscia/pkg/utils/supervisor"
Expand Down Expand Up @@ -87,7 +87,7 @@ func NewEnvoy(i *Dependencies) Module {
}

func (s *envoyModule) Run(ctx context.Context) error {
if err := os.MkdirAll(filepath.Join(s.rootDir, confloader.LogPrefix, "envoy/"), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(s.rootDir, common.LogPrefix, "envoy/"), 0755); err != nil {
return err
}
deltaArgs, err := s.readCommandArgs()
Expand All @@ -97,13 +97,13 @@ func (s *envoyModule) Run(ctx context.Context) error {

args := []string{
"-c",
filepath.Join(s.rootDir, confloader.ConfPrefix, "envoy/envoy.yaml"),
filepath.Join(s.rootDir, common.ConfPrefix, "envoy/envoy.yaml"),
"--service-cluster",
s.cluster,
"--service-node",
s.id,
"--log-path",
filepath.Join(s.rootDir, confloader.LogPrefix, "envoy/envoy.log"),
filepath.Join(s.rootDir, common.LogPrefix, "envoy/envoy.log"),
}
args = append(args, deltaArgs.Args...)
sp := supervisor.NewSupervisor("envoy", nil, -1)
Expand All @@ -129,7 +129,7 @@ func (s *envoyModule) logRotate(ctx context.Context) {

time.Sleep(d)

cmd := exec.Command("logrotate", filepath.Join(s.rootDir, confloader.ConfPrefix, "logrotate.conf"))
cmd := exec.Command("logrotate", filepath.Join(s.rootDir, common.ConfPrefix, "logrotate.conf"))
if err := cmd.Run(); err != nil {
nlog.Errorf("Logrotate run error: %v", err)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (s *envoyModule) Name() string {
}

func (s *envoyModule) readCommandArgs() (*EnvoyCommandLineConfig, error) {
configPath := filepath.Join(s.rootDir, confloader.ConfPrefix, s.commandLineConfigFile)
configPath := filepath.Join(s.rootDir, common.ConfPrefix, s.commandLineConfigFile)
data, err := os.ReadFile(configPath)
if err != nil {
return nil, err
Expand Down
17 changes: 8 additions & 9 deletions cmd/kuscia/modules/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

"github.com/google/uuid"

"github.com/secretflow/kuscia/cmd/kuscia/confloader"
pkgcom "github.com/secretflow/kuscia/pkg/common"
"github.com/secretflow/kuscia/pkg/utils/common"
"github.com/secretflow/kuscia/pkg/utils/network"
"github.com/secretflow/kuscia/pkg/utils/nlog/ljwriter"
Expand Down Expand Up @@ -128,7 +128,6 @@ func NewK3s(i *Dependencies) Module {
if clusterToken == "" {
clusterToken = fmt.Sprintf("%x", md5.Sum([]byte(i.DomainID)))
}
nlog.Infof("ClusterToken is: %s", clusterToken)
hostIP, err := network.GetHostIP()
if err != nil {
nlog.Fatal(err)
Expand Down Expand Up @@ -176,15 +175,15 @@ func (s *k3sModule) Run(ctx context.Context) error {
}
if s.enableAudit {
args = append(args,
"--kube-apiserver-arg=audit-log-path="+filepath.Join(s.rootDir, confloader.LogPrefix, "k3s-audit.log"),
"--kube-apiserver-arg=audit-policy-file="+filepath.Join(s.rootDir, confloader.ConfPrefix, "k3s/k3s-audit-policy.yaml"),
"--kube-apiserver-arg=audit-log-path="+filepath.Join(s.rootDir, pkgcom.LogPrefix, "k3s-audit.log"),
"--kube-apiserver-arg=audit-policy-file="+filepath.Join(s.rootDir, pkgcom.ConfPrefix, "k3s/k3s-audit-policy.yaml"),
"--kube-apiserver-arg=audit-log-maxbackup=10",
"--kube-apiserver-arg=audit-log-maxsize=300",
)
}

sp := supervisor.NewSupervisor("k3s", nil, -1)
s.LogConfig.LogPath = filepath.Join(s.rootDir, confloader.LogPrefix, "k3s.log")
s.LogConfig.LogPath = filepath.Join(s.rootDir, pkgcom.LogPrefix, "k3s.log")
lj, _ := ljwriter.New(&s.LogConfig)
n := nlog.NewNLog(nlog.SetWriter(lj))

Expand Down Expand Up @@ -274,9 +273,9 @@ func genKusciaKubeConfig(conf *Dependencies) error {
serverCertFile: filepath.Join(conf.RootDir, k3sDataDirPrefix, "server/tls/server-ca.crt"),
clientKeyFile: filepath.Join(conf.RootDir, k3sDataDirPrefix, "server/tls/client-ca.key"),
clientCertFile: filepath.Join(conf.RootDir, k3sDataDirPrefix, "server/tls/client-ca.crt"),
clusterRoleFile: filepath.Join(conf.RootDir, confloader.ConfPrefix, "kuscia-clusterrole.yaml"),
clusterRoleBindingFile: filepath.Join(conf.RootDir, confloader.ConfPrefix, "kuscia-clusterrolebinding.yaml"),
kubeConfigTmplFile: filepath.Join(conf.RootDir, confloader.ConfPrefix, "kuscia.kubeconfig.tmpl"),
clusterRoleFile: filepath.Join(conf.RootDir, pkgcom.ConfPrefix, "kuscia-clusterrole.yaml"),
clusterRoleBindingFile: filepath.Join(conf.RootDir, pkgcom.ConfPrefix, "kuscia-clusterrolebinding.yaml"),
kubeConfigTmplFile: filepath.Join(conf.RootDir, pkgcom.ConfPrefix, "kuscia.kubeconfig.tmpl"),
kubeConfig: conf.KusciaKubeConfig,
}

Expand Down Expand Up @@ -341,7 +340,7 @@ func genKusciaKubeConfig(conf *Dependencies) error {
func applyKusciaResources(conf *Dependencies) error {
// apply kuscia clusterRole
resourceFiles := []string{
filepath.Join(conf.RootDir, confloader.ConfPrefix, "domain-cluster-res.yaml"),
filepath.Join(conf.RootDir, pkgcom.ConfPrefix, "domain-cluster-res.yaml"),
}
sw := sync.WaitGroup{}
for _, file := range resourceFiles {
Expand Down
Loading

0 comments on commit c4b58da

Please sign in to comment.