Skip to content

Commit

Permalink
Add support reset components to nightly (#45)
Browse files Browse the repository at this point in the history
* Add support reset components to nightly

* Add go sec check

* Fix the issues found by gosec
  • Loading branch information
LinuxSuRen authored Jan 29, 2021
1 parent 6bdcb9d commit 5e8f983
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,29 @@ jobs:
uses: Jerome1337/[email protected]
with:
golint-path: ./...
Security:
name: Security
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v2
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: '-exclude=G402,G204,G304,G110 ./...'
CodeQL:
name: CodeQL
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: go
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion kubectl-plugin/auth/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "gopkg.in/yaml.v3"

func updateAuthentication(yamlf, name, target string) string {
targetobj := make(map[string]interface{}, 0)
yaml.Unmarshal([]byte(target), targetobj)
_ = yaml.Unmarshal([]byte(target), targetobj)
return updateAuthWithObj(yamlf, name, targetobj)
}

Expand Down
1 change: 1 addition & 0 deletions kubectl-plugin/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ResetOption struct {
Option

ResetAll bool
Nightly string
}

// WatchOption is the option for component watch command
Expand Down
18 changes: 17 additions & 1 deletion kubectl-plugin/component/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
kstypes "github.com/linuxsuren/ks/kubectl-plugin/types"
"github.com/spf13/cobra"
"k8s.io/client-go/dynamic"
"time"
)

// NewComponentResetCmd returns a command to enable (or disable) a component by name
Expand All @@ -18,7 +19,8 @@ func NewComponentResetCmd(client dynamic.Interface) (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "reset",
Short: "reset the component by name",
Example: `'kubectl ks com reset -r=false -a' will reset ks-apiserver, ks-controller-manager, ks-console to the latest`,
Example: `'kubectl ks com reset -r=false -a' will reset ks-apiserver, ks-controller-manager, ks-console to the latest
kubectl ks com reset -a --nightly latest`,
RunE: opt.resetRunE,
}

Expand All @@ -29,6 +31,8 @@ func NewComponentResetCmd(client dynamic.Interface) (cmd *cobra.Command) {
"The tag of KubeSphere deploys")
flags.BoolVarP(&opt.ResetAll, "all", "a", false,
"Indicate if you want to all supported components")
flags.StringVarP(&opt.Nightly, "nightly", "", "",
"Indicate if you want to update component to nightly build. It should be date, e.g. 2021-01-01. Or you can just use latest represents the last day")
flags.StringVarP(&opt.Name, "name", "n", "",
"The name of target component which you want to reset. This does not work if you provide flag --all")
return
Expand Down Expand Up @@ -63,6 +67,18 @@ func (o *ResetOption) resetRunE(cmd *cobra.Command, args []string) (err error) {
o.Tag = "latest"
}

// try to parse the nightly date
if o.Nightly == "latest" {
imageOrg = "kubespheredev"
o.Tag = fmt.Sprintf("nightly-%s", time.Now().AddDate(0, 0, -1).Format("20060102"))
} else if o.Nightly != "" {
layout := "2006-01-02"
var targetDate time.Time
if targetDate, err = time.Parse(layout, o.Nightly); err == nil {
o.Tag = targetDate.Format("20060102")
}
}

if o.ResetAll {
o.Name = "apiserver"
if err = o.updateBy(imageOrg, o.Tag); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions kubectl-plugin/registry/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func NewRegistryCmd(client dynamic.Interface) (cmd *cobra.Command) {
After that, please restart docker daemon via: systemctl restart docker
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
client.Resource(types.GetDeploySchema()).Namespace("default").Delete(ctx, "registry", metav1.DeleteOptions{})
client.Resource(types.GetServiceSchema()).Namespace("default").Delete(ctx, "registry", metav1.DeleteOptions{})
_ = client.Resource(types.GetDeploySchema()).Namespace("default").Delete(ctx, "registry", metav1.DeleteOptions{})
_ = client.Resource(types.GetServiceSchema()).Namespace("default").Delete(ctx, "registry", metav1.DeleteOptions{})

obj := &unstructured.Unstructured{}
content := getRegistryDeploy()
Expand Down
6 changes: 3 additions & 3 deletions kubectl-plugin/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ func (o *updateCmdOption) RunE(cmd *cobra.Command, args []string) (err error) {
imageOrg = "kubesphere"
}

o.updateDeploy("kubesphere-system", "ks-apiserver", fmt.Sprintf("%s/ks-apiserver", imageOrg), o.Tag)
o.updateDeploy("kubesphere-system", "ks-controller-manager", fmt.Sprintf("%s/ks-controller-manager", imageOrg), o.Tag)
o.updateDeploy("kubesphere-system", "ks-console", fmt.Sprintf("%s/ks-console", imageOrg), o.Tag)
_ = o.updateDeploy("kubesphere-system", "ks-apiserver", fmt.Sprintf("%s/ks-apiserver", imageOrg), o.Tag)
_ = o.updateDeploy("kubesphere-system", "ks-controller-manager", fmt.Sprintf("%s/ks-controller-manager", imageOrg), o.Tag)
_ = o.updateDeploy("kubesphere-system", "ks-console", fmt.Sprintf("%s/ks-console", imageOrg), o.Tag)
return
}

Expand Down

0 comments on commit 5e8f983

Please sign in to comment.