cleanup: remove unused code and fix typo (#5986)

Signed-off-by: yyzxw <1020938856@qq.com>
Signed-off-by: xiaowu.zhu <xiaowu.zhu@daocloud.io>
Co-authored-by: xiaowu.zhu <xiaowu.zhu@daocloud.io>
This commit is contained in:
yyzxw
2023-05-16 12:37:00 +08:00
committed by GitHub
parent e0d106024b
commit 1af82cd282
18 changed files with 37 additions and 46 deletions

View File

@@ -100,7 +100,7 @@ func (g *giteeReader) listAddonMeta(dirPath string) ([]Item, error) {
return res, nil
}
// ReadFile read file content from github
// ReadFile read file content from gitee
func (g *giteeReader) ReadFile(relativePath string) (content string, err error) {
file, _, err := g.h.readRepo(relativePath)
if err != nil {

View File

@@ -100,7 +100,7 @@ func (o *ossReader) ListAddonMeta() (map[string]SourceMeta, error) {
}
// convertOSSFiles2Addons convert OSS list result to map of addon meta information
func (o ossReader) convertOSSFiles2Addons(files []File) map[string]SourceMeta {
func (o *ossReader) convertOSSFiles2Addons(files []File) map[string]SourceMeta {
addonMetas := make(map[string]SourceMeta)
pathBuckets := make(map[string][]Item)
fPaths := make(map[string][]string)

View File

@@ -118,7 +118,7 @@ func (p *Parser) GenerateAppFileFromApp(ctx context.Context, app *v1beta1.Applic
}
}
appfile := p.newAppfile(appName, ns, app)
appfile := p.newAppFile(appName, ns, app)
if app.Status.LatestRevision != nil {
appfile.AppRevisionName = app.Status.LatestRevision.Name
}
@@ -176,7 +176,7 @@ func (p *Parser) GenerateAppFileFromApp(ctx context.Context, app *v1beta1.Applic
return appfile, nil
}
func (p *Parser) newAppfile(appName, ns string, app *v1beta1.Application) *Appfile {
func (p *Parser) newAppFile(appName, ns string, app *v1beta1.Application) *Appfile {
file := &Appfile{
Name: appName,
Namespace: ns,
@@ -260,7 +260,7 @@ func (p *Parser) GenerateAppFileFromRevision(appRev *v1beta1.ApplicationRevision
app := appRev.Spec.Application.DeepCopy()
ns := app.Namespace
appName := app.Name
appfile := p.newAppfile(appName, ns, app)
appfile := p.newAppFile(appName, ns, app)
appfile.AppRevision = appRev
appfile.AppRevisionName = appRev.Name
appfile.AppRevisionHash = appRev.Labels[oam.LabelAppRevisionHash]

View File

@@ -118,7 +118,7 @@ type Template struct {
// System: The system users could use this template, and the config secret will save in the vela-system namespace.
// Namespace: The config secret will save in the target namespace, such as this namespace belonging to one project.
Scope string `json:"scope"`
// Sensitive means this config config can not be read from the API or the workflow step, only support the safe way, such as Secret.
// Sensitive means this config can not be read from the API or the workflow step, only support the safe way, such as Secret.
Sensitive bool `json:"sensitive"`
CreateTime time.Time `json:"createTime"`

View File

@@ -114,12 +114,12 @@ func (p *provider) List(ctx monitorContext.Context, wfCtx wfContext.Context, v *
return err
}
var contents = []map[string]interface{}{}
for _, config := range configs {
for _, c := range configs {
contents = append(contents, map[string]interface{}{
"name": config.Name,
"alias": config.Alias,
"description": config.Description,
"config": config.Properties,
"name": c.Name,
"alias": c.Alias,
"description": c.Description,
"config": c.Properties,
})
}
return v.FillObject(contents, "configs")

View File

@@ -782,9 +782,9 @@ func (h *AppHandler) createControllerRevision(ctx context.Context, cm *types.Com
}
func componentManifest2Component(cm *types.ComponentManifest) (*v1alpha2.Component, error) {
component := &v1alpha2.Component{}
component.SetGroupVersionKind(v1alpha2.ComponentGroupVersionKind)
component.SetName(cm.Name)
c := &v1alpha2.Component{}
c.SetGroupVersionKind(v1alpha2.ComponentGroupVersionKind)
c.SetName(cm.Name)
wl := &unstructured.Unstructured{}
if cm.StandardWorkload != nil {
// use revision name replace compRev placeHolder
@@ -794,7 +794,7 @@ func componentManifest2Component(cm *types.ComponentManifest) (*v1alpha2.Compone
wl = cm.StandardWorkload.DeepCopy()
util.RemoveLabels(wl, []string{oam.LabelAppRevision})
}
component.Spec.Workload = *util.Object2RawExtension(wl)
c.Spec.Workload = *util.Object2RawExtension(wl)
if len(cm.PackagedWorkloadResources) > 0 {
helm := &common.Helm{}
for _, helmResource := range cm.PackagedWorkloadResources {
@@ -805,9 +805,9 @@ func componentManifest2Component(cm *types.ComponentManifest) (*v1alpha2.Compone
helm.Repository = *util.Object2RawExtension(helmResource)
}
}
component.Spec.Helm = helm
c.Spec.Helm = helm
}
return component, nil
return c, nil
}
// FinalizeAndApplyAppRevision finalise AppRevision object and apply it

View File

@@ -747,7 +747,7 @@ func (def *CapabilityBaseDefinition) CreateOrUpdateConfigMap(ctx context.Context
// getOpenAPISchema is the main function for GetDefinition API
func getOpenAPISchema(capability types.Capability) ([]byte, error) {
cueTemplate := script.CUE([]byte(capability.CueTemplate))
cueTemplate := script.CUE(capability.CueTemplate)
schema, err := cueTemplate.ParsePropertiesToSchema()
if err != nil {
return nil, err

View File

@@ -220,14 +220,14 @@ func (c CUE) ValidateProperties(properties map[string]interface{}) error {
newCue := strings.Builder{}
newCue.WriteString(parameterStr + "\n")
newCue.WriteString(string(propertiesByte) + "\n")
value, err := value.NewValue(newCue.String(), nil, "")
newValue, err := value.NewValue(newCue.String(), nil, "")
if err != nil {
return ConvertFieldError(err)
}
if err := value.CueValue().Validate(); err != nil {
if err := newValue.CueValue().Validate(); err != nil {
return ConvertFieldError(err)
}
_, err = value.CueValue().MarshalJSON()
_, err = newValue.CueValue().MarshalJSON()
if err != nil {
return ConvertFieldError(err)
}

View File

@@ -288,12 +288,12 @@ func TestValidatePropertiesWithCueX(t *testing.T) {
}
func TestParsePropertiesToSchema(t *testing.T) {
cue := CUE([]byte(withPackage))
cue := CUE(withPackage)
schema, err := cue.ParsePropertiesToSchema()
assert.Equal(t, err, nil)
assert.Equal(t, len(schema.Properties), 10)
cue = CUE([]byte(withImport))
cue = CUE(withImport)
schema, err = cue.ParsePropertiesToSchema()
assert.Equal(t, err, nil)
assert.Equal(t, len(schema.Properties), 2)

View File

@@ -88,7 +88,7 @@ func NewMock() *httptest.Server {
if r.URL.EscapedPath() != "/api/v1/token" {
fmt.Printf("Expected request to '/person', got '%s'", r.URL.EscapedPath())
}
r.ParseForm()
_ = r.ParseForm()
token := r.Form.Get("val")
tokenBytes, _ := json.Marshal(map[string]interface{}{"token": token})
@@ -96,7 +96,7 @@ func NewMock() *httptest.Server {
w.Write(tokenBytes)
}))
l, _ := net.Listen("tcp", "127.0.0.1:8090")
ts.Listener.Close()
_ = ts.Listener.Close()
ts.Listener = l
ts.Start()
return ts

View File

@@ -2,7 +2,7 @@
## Context
First, this context is compatible with built-in context interface.
Also it supports fork and commit like trace span.
Also, it supports fork and commit like trace span.
### Fork
`Fork` will generate a sub context that inherit the parent's tags. When new tags are added to the `sub-context`, the `parent-context` will not be affected.

View File

@@ -275,16 +275,16 @@ func SetEnvLabels(envArgs *types.EnvMeta) error {
if err != nil {
return err
}
labels, err := labels.ConvertSelectorToLabelsMap(envArgs.Labels)
labelsMap, err := labels.ConvertSelectorToLabelsMap(envArgs.Labels)
if err != nil {
return err
}
namespace.Labels = util.MergeMapOverrideWithDst(namespace.GetLabels(), labels)
namespace.Labels = util.MergeMapOverrideWithDst(namespace.GetLabels(), labelsMap)
err = c.Update(context.Background(), namespace)
if err != nil {
return errors.Wrapf(err, "fail to set env labels")
return errors.Wrapf(err, "fail to set env labelsMap")
}
return nil
}

View File

@@ -68,7 +68,7 @@ func EqualSlice(a, b []string) bool {
return reflect.DeepEqual(a, b)
}
// SliceIncludeSlice the a slice include the b slice
// SliceIncludeSlice the slice include the b slice
func SliceIncludeSlice(a, b []string) bool {
if EqualSlice(a, b) {
return true

View File

@@ -152,12 +152,3 @@ func validateRolloutBatches(rollout *v1alpha1.RolloutPlan, rootPath *field.Path)
}
return allErrs
}
// ValidateUpdate validate if one can change the rollout plan from the previous psec
func ValidateUpdate(client client.Client, new *v1alpha1.RolloutPlan, prev *v1alpha1.RolloutPlan,
rootPath *field.Path) field.ErrorList {
// TODO: Enforce that only a few fields can change after a rollout plan is set
var allErrs field.ErrorList
return allErrs
}

View File

@@ -110,11 +110,11 @@ func NewClusterListCommand(c *common.Args) *cobra.Command {
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
table := newUITable().AddRow("CLUSTER", "ALIAS", "TYPE", "ENDPOINT", "ACCEPTED", "LABELS")
client, err := c.GetClient()
clsClient, err := c.GetClient()
if err != nil {
return err
}
clusters, err := multicluster.NewClusterClient(client).List(context.Background())
clusters, err := multicluster.NewClusterClient(clsClient).List(context.Background())
if err != nil {
return errors.Wrap(err, "fail to get registered cluster")
}

View File

@@ -144,7 +144,7 @@ func NewTemplateListCommand(f velacmd.Factory, streams util.IOStreams) *cobra.Co
if options.AllNamespace {
options.Namespace = ""
}
templates, err := inf.ListTemplates(context.Background(), options.Namespace, "")
templateList, err := inf.ListTemplates(context.Background(), options.Namespace, "")
if err != nil {
return err
}
@@ -154,7 +154,7 @@ func NewTemplateListCommand(f velacmd.Factory, streams util.IOStreams) *cobra.Co
header = append([]interface{}{"NAMESPACE"}, header...)
}
table.AddRow(header...)
for _, t := range templates {
for _, t := range templateList {
row := []interface{}{t.Name, t.Alias, t.Scope, t.Sensitive, t.CreateTime}
if options.AllNamespace {
row = append([]interface{}{t.Namespace}, row...)

View File

@@ -129,7 +129,7 @@ func DryRunApplication(cmdOption *DryRunCmdOptions, c common.Args, namespace str
var err error
var buff = bytes.Buffer{}
objs := []oam.Object{}
var objs []oam.Object
if cmdOption.DefinitionFile != "" {
objs, err = ReadDefinitionsFromFile(cmdOption.DefinitionFile)
if err != nil {

View File

@@ -171,8 +171,8 @@ func ListEnvs(args []string, ioStreams cmdutil.IOStreams) error {
if err != nil {
return err
}
for _, env := range envList {
table.AddRow(env.Name, env.Namespace, env.Current)
for _, envMeta := range envList {
table.AddRow(envMeta.Name, envMeta.Namespace, envMeta.Current)
}
ioStreams.Info(table.String())
return nil