Skip to content

Commit

Permalink
fix: Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Oct 18, 2024
1 parent 88708e9 commit a54a10b
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/cce.pandaria.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type CCEClusterPublicIP struct {
}

type CCENodePublicIP struct {
Ids []string `json:"ids,omitempty"` // 已有的弹性IP的ID列表。数量不得大于待创建节点数
IDs []string `json:"ids,omitempty"` // 已有的弹性IP的ID列表。数量不得大于待创建节点数
Count int32 `json:"count,omitempty"` // 要动态创建的弹性IP个数。
Eip CCEEip `json:"eip,omitempty"` // 弹性IP参数。
}
Expand All @@ -187,7 +187,7 @@ type CCEClusterExtendParam struct {
}

type CCEClusterEndpoints struct {
Url string `json:"url,omitempty"`
URL string `json:"url,omitempty"`
Type string `json:"type,omitempty"`
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/cce.pandaria.io/v1/zz_generated_deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newCRD(obj interface{}, customize func(crd.CRD) crd.CRD) crd.CRD {

func saveCRDYaml(name, data string) error {
filename := fmt.Sprintf("./charts/%s/templates/crds.yaml", name)
if err := os.WriteFile(filename, []byte(data), 0644); err != nil {
if err := os.WriteFile(filename, []byte(data), 0600); err != nil {
return err
}

Expand Down
11 changes: 5 additions & 6 deletions pkg/controller/cce-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (h *Handler) generateAndSetNetworking(config *ccev1.CCEClusterConfig) (*cce
if dnsServers.Nameservers == nil || len(*dnsServers.Nameservers) == 0 {
return config, fmt.Errorf("ListNameServers returns invalid data")
}
var dnsRecords []string = make([]string, 2)
var dnsRecords = make([]string, 2)
for _, nameserver := range *dnsServers.Nameservers {
if nameserver.NsRecords == nil || len(*nameserver.NsRecords) == 0 {
continue
Expand Down Expand Up @@ -387,7 +387,7 @@ func (h *Handler) generateAndSetNetworking(config *ccev1.CCEClusterConfig) (*cce
if dnsServers.Nameservers == nil || len(*dnsServers.Nameservers) == 0 {
return config, fmt.Errorf("ListNameServers returns invalid data")
}
var dnsRecords []string = make([]string, 2)
var dnsRecords = make([]string, 2)
for _, nameserver := range *dnsServers.Nameservers {
if nameserver.NsRecords == nil || len(*nameserver.NsRecords) == 0 {
continue
Expand Down Expand Up @@ -661,9 +661,8 @@ func (h *Handler) checkAndUpdate(config *ccev1.CCEClusterConfig) (*ccev1.CCEClus
config = config.DeepCopy()
config.Status.UpgradeClusterTaskID = ""
return h.cceCC.UpdateStatus(config)
} else {
return config, err
}
return config, err
}
if res != nil && res.Spec != nil && res.Status != nil {
switch utils.Value(res.Status.Phase) {
Expand Down Expand Up @@ -722,7 +721,7 @@ func (h *Handler) checkAndUpdate(config *ccev1.CCEClusterConfig) (*ccev1.CCEClus
if len(configUpdate.Status.Endpoints) == len(*cluster.Status.Endpoints) {
for i := range *cluster.Status.Endpoints {
if configUpdate.Status.Endpoints[i].Type != utils.Value((*cluster.Status.Endpoints)[i].Type) ||
configUpdate.Status.Endpoints[i].Url != utils.Value((*cluster.Status.Endpoints)[i].Url) {
configUpdate.Status.Endpoints[i].URL != utils.Value((*cluster.Status.Endpoints)[i].Url) {
updateEndpoints = true
}
}
Expand All @@ -734,7 +733,7 @@ func (h *Handler) checkAndUpdate(config *ccev1.CCEClusterConfig) (*ccev1.CCEClus
configUpdate.Status.Endpoints = nil
for _, e := range *cluster.Status.Endpoints {
configUpdate.Status.Endpoints = append(configUpdate.Status.Endpoints, ccev1.CCEClusterEndpoints{
Url: utils.Value(e.Url),
URL: utils.Value(e.Url),
Type: utils.Value(e.Type),
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewHuaweiDriver(auth *common.ClientAuth) *HuaweiDriver {
VPC: vpc.NewVpcClient(auth),
EIP: eip.NewEipClient(auth),
VPCEP: vpcep.NewVpcepClient(auth),
DNS: dns.NewDnsClient(auth),
DNS: dns.NewDNSClient(auth),
NAT: nat.NewNatClient(auth),
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func BuildUpstreamNodePoolConfigs(
if nodePools == nil || nodePools.Items == nil {
return nil, fmt.Errorf("BuildUpstreamNodePoolConfigs: invalid nil parameter")
}
var nps []ccev1.CCENodePool = make([]ccev1.CCENodePool, 0, len(*nodePools.Items))
var nps = make([]ccev1.CCENodePool, 0, len(*nodePools.Items))
if len(*nodePools.Items) == 0 {
return nps, nil
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func BuildUpstreamNodePoolConfigs(
}
}
if np.Spec.NodeTemplate.PublicIP != nil {
config.NodeTemplate.PublicIP.Ids = utils.Value(np.Spec.NodeTemplate.PublicIP.Ids)
config.NodeTemplate.PublicIP.IDs = utils.Value(np.Spec.NodeTemplate.PublicIP.Ids)
config.NodeTemplate.PublicIP.Count = utils.Value(np.Spec.NodeTemplate.Count)
if np.Spec.NodeTemplate.PublicIP.Eip != nil {
config.NodeTemplate.PublicIP.Eip.Iptype = np.Spec.NodeTemplate.PublicIP.Eip.Iptype
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ func validateNodePool(config *ccev1.CCEClusterConfig) error {
}
if nodePoolNames[pool.Name] {
return fmt.Errorf("nodePool.name should be unique, duplicated detected: %q", pool.Name)
} else {
nodePoolNames[pool.Name] = true
}
nodePoolNames[pool.Name] = true
nt := pool.NodeTemplate
if nt.Flavor == "" {
return fmt.Errorf(cannotBeEmptyError, "nodePool.nodeTemplate.flavor", config.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/huawei/cce/cce.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func GetCreateClusterRequest(config *ccev1.CCEClusterConfig) *model.CreateCluste
kubeProxyMode = model.GetClusterSpecKubeProxyModeEnum().IPTABLES
}

var clusterTags []model.ResourceTag
var clusterTags = make([]model.ResourceTag, 0)
for k, v := range spec.Tags {
clusterTags = append(clusterTags, model.ResourceTag{
Key: utils.Pointer(k),
Expand Down
4 changes: 2 additions & 2 deletions pkg/huawei/cce/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ func GetCreateNodePoolRequest(
)
}

if len(np.NodeTemplate.PublicIP.Ids) > 0 {
nodePoolBody.Spec.NodeTemplate.PublicIP.Ids = &np.NodeTemplate.PublicIP.Ids
if len(np.NodeTemplate.PublicIP.IDs) > 0 {
nodePoolBody.Spec.NodeTemplate.PublicIP.Ids = &np.NodeTemplate.PublicIP.IDs
}
chargeMode := "traffic"
if np.NodeTemplate.PublicIP.Eip.Bandwidth.ChargeMode != "traffic" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/huawei/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
)

func NewDnsClient(c *common.ClientAuth) *dns.DnsClient {
func NewDNSClient(c *common.ClientAuth) *dns.DnsClient {
return dns.NewDnsClient(
dns.DnsClientBuilder().
WithRegion(region.ValueOf(c.Region)).
Expand Down
12 changes: 6 additions & 6 deletions pkg/huawei/huawei.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ import (
"encoding/json"
)

type HuaweiError struct {
type Error struct {
StatusCode int32 `json:"status_code,omitempty"`
RequestID string `json:"request_id,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
}

func NewHuaweiError(err error) (*HuaweiError, error) {
func NewHuaweiError(err error) (*Error, error) {
var errMsg string
if err != nil {
errMsg = err.Error()
}
d := json.NewDecoder(bytes.NewBufferString(errMsg))
huaweiError := &HuaweiError{}
huaweiError := &Error{}
err = d.Decode(huaweiError)
return huaweiError, err
}

func IsHuaweiError(err error) bool {
d := json.NewDecoder(bytes.NewBufferString(err.Error()))
h := &HuaweiError{}
h := &Error{}
if err := d.Decode(h); err != nil {
return false
}
return true
}

func (e *HuaweiError) String() string {
func (e *Error) String() string {
d, _ := json.Marshal(e)
return string(d)
}

func (e *HuaweiError) MarshalIndent() string {
func (e *Error) MarshalIndent() string {
d, _ := json.MarshalIndent(e, "", " ")
return string(d)
}
12 changes: 8 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package utils

import (
"crypto/rand"
"encoding/json"
"math/rand"
"math/big"
"strings"
"time"
)

func PrintObject(a any) string {
Expand All @@ -22,11 +22,15 @@ func Parse(ref string) (namespace string, name string) {

// Generates a random hexadecimal number.
func RandomHex(l int) string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
chars := []byte("abcdef0123456789")
big := new(big.Int).SetInt64(int64(len(chars)))
var b strings.Builder
for i := 0; i < l; i++ {
b.WriteByte(chars[r.Intn(len(chars))])
i, err := rand.Int(rand.Reader, big)
if err != nil {
return ""
}
b.WriteByte(chars[i.Int64()])
}

return b.String()
Expand Down

0 comments on commit a54a10b

Please sign in to comment.