Skip to content

Commit

Permalink
Enable gofumpt linter instead of gofmt (clusterlink-net#255)
Browse files Browse the repository at this point in the history
* replace gofmt linter with gofumpt
* use octal representation
* fix closing brace indentation

Signed-off-by: Etai Lev Ran <[email protected]>
  • Loading branch information
elevran authored Jan 7, 2024
1 parent 2224e40 commit b751c70
Show file tree
Hide file tree
Showing 35 changed files with 85 additions and 59 deletions.
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ linters:
- ginkgolinter
- gocritic
- godot
- gofmt
# - gofumpt
- gofumpt
- goimports
- gomoddirectives
- gosec
Expand Down
4 changes: 2 additions & 2 deletions cmd/cl-adm/cmd/create/create_fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func NewCmdCreateFabric() *cobra.Command {
}

// save certificate to file
err = os.WriteFile(config.CertificateFileName, fabricCert.RawCert(), 0600)
err = os.WriteFile(config.CertificateFileName, fabricCert.RawCert(), 0o600)
if err != nil {
return err
}

// save private key to file
return os.WriteFile(config.PrivateKeyFileName, fabricCert.RawKey(), 0600)
return os.WriteFile(config.PrivateKeyFileName, fabricCert.RawKey(), 0o600)
},
}
}
14 changes: 7 additions & 7 deletions cmd/cl-adm/cmd/create/create_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (o *PeerOptions) RequiredFlags() []string {

func (o *PeerOptions) saveCertificate(cert *bootstrap.Certificate, outDirectory string) error {
// save certificate to file
err := os.WriteFile(filepath.Join(outDirectory, config.CertificateFileName), cert.RawCert(), 0600)
err := os.WriteFile(filepath.Join(outDirectory, config.CertificateFileName), cert.RawCert(), 0o600)
if err != nil {
return err
}

// save private key to file
return os.WriteFile(filepath.Join(outDirectory, config.PrivateKeyFileName), cert.RawKey(), 0600)
return os.WriteFile(filepath.Join(outDirectory, config.PrivateKeyFileName), cert.RawKey(), 0o600)
}

func (o *PeerOptions) createControlplane(peerCert *bootstrap.Certificate) (*bootstrap.Certificate, error) {
Expand All @@ -73,7 +73,7 @@ func (o *PeerOptions) createControlplane(peerCert *bootstrap.Certificate) (*boot
}

outDirectory := config.ControlplaneDirectory(o.Name)
if err := os.Mkdir(outDirectory, 0755); err != nil {
if err := os.Mkdir(outDirectory, 0o755); err != nil {
return nil, err
}

Expand All @@ -91,7 +91,7 @@ func (o *PeerOptions) createDataplane(peerCert *bootstrap.Certificate) (*bootstr
}

outDirectory := config.DataplaneDirectory(o.Name)
if err := os.Mkdir(outDirectory, 0755); err != nil {
if err := os.Mkdir(outDirectory, 0o755); err != nil {
return nil, err
}

Expand All @@ -109,7 +109,7 @@ func (o *PeerOptions) createGWCTL(peerCert *bootstrap.Certificate) (*bootstrap.C
}

outDirectory := config.GWCTLDirectory(o.Name)
if err := os.Mkdir(outDirectory, 0755); err != nil {
if err := os.Mkdir(outDirectory, 0o755); err != nil {
return nil, err
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func (o *PeerOptions) Run() error {
}

peerDirectory := config.PeerDirectory(o.Name)
if err := os.Mkdir(peerDirectory, 0755); err != nil {
if err := os.Mkdir(peerDirectory, 0o755); err != nil {
return err
}

Expand Down Expand Up @@ -199,7 +199,7 @@ func (o *PeerOptions) Run() error {
}

outPath := filepath.Join(peerDirectory, config.K8SYamlFile)
return os.WriteFile(outPath, k8sConfig, 0600)
return os.WriteFile(outPath, k8sConfig, 0o600)
}

// NewCmdCreatePeer returns a cobra.Command to run the 'create peer' subcommand.
Expand Down
2 changes: 1 addition & 1 deletion cmd/cl-dataplane/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (o *Options) RequiredFlags() []string {
func (o *Options) Run() error {
// set log file
if o.LogFile != "" {
f, err := os.OpenFile(o.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
f, err := os.OpenFile(o.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0o666)
if err != nil {
return fmt.Errorf("unable to open log file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cl-go-dataplane/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (o *Options) runGoDataplane(peerName, dataplaneID string, parsedCertData *u
func (o *Options) Run() error {
// set log file
if o.LogFile != "" {
f, err := os.OpenFile(o.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
f, err := os.OpenFile(o.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0o666)
if err != nil {
return fmt.Errorf("unable to open log file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gwctl/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *ClientConfig) createProjectfolder() (string, error) {
}
fol := path.Join(usr.HomeDir, projectFolder)
// Create folder
err = os.MkdirAll(fol, 0755)
err = os.MkdirAll(fol, 0o755)
if err != nil {
c.logger.Errorln(err)
return "", err
Expand All @@ -152,7 +152,7 @@ func (c *ClientConfig) createConfigFile() error {
c.logger.Errorln("Client get config file path", err)
return err
}
err = os.WriteFile(f, jsonC, 0600) // RW by owner only
err = os.WriteFile(f, jsonC, 0o600) // RW by owner only
c.logger.Println("Create Client config File:", f)
if err != nil {
c.logger.Errorln("Creating client config File", err)
Expand Down
6 changes: 4 additions & 2 deletions cmd/gwctl/subcommand/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func (o *bindingCreateOptions) run() error {
err = g.Bindings.Create(&api.Binding{
Spec: api.BindingSpec{
Import: o.importID,
Peer: o.peer},
Peer: o.peer,
},
})
if err != nil {
return err
Expand Down Expand Up @@ -118,7 +119,8 @@ func (o *bindingDeleteOptions) run() error {
err = g.Bindings.Delete(&api.Binding{
Spec: api.BindingSpec{
Import: o.importID,
Peer: o.peer},
Peer: o.peer,
},
})
if err != nil {
return err
Expand Down
4 changes: 1 addition & 3 deletions cmd/gwctl/subcommand/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ func ConfigCmd() *cobra.Command {
}

// getContextCmd is the command line options for 'config current-context'.
type currentContextOptions struct {
}
type currentContextOptions struct{}

// currentContextCmd - get the last gwctl context command to use.
func currentContextCmd() *cobra.Command {
o := currentContextOptions{}
cmd := &cobra.Command{

Use: "current-context",
Short: "Get gwctl current context.",
Long: `Get gwctl current context.`,
Expand Down
3 changes: 2 additions & 1 deletion cmd/gwctl/subcommand/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func (o *exportCreateOptions) run(isUpdate bool) error {
Spec: api.ExportSpec{
Service: api.Endpoint{
Host: o.host,
Port: o.port},
Port: o.port,
},
ExternalService: o.external,
},
})
Expand Down
3 changes: 2 additions & 1 deletion cmd/gwctl/subcommand/gwctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func (o *initOptions) run() error {
CertFile: o.cert,
KeyFile: o.key,
Dataplane: o.dataplane,
PolicyEngineIP: o.policyEngineIP})
PolicyEngineIP: o.policyEngineIP,
})

return err
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/gwctl/subcommand/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func ImportCreateCmd() *cobra.Command {
Long: `Create an imported service that can be bounded to other peers`,
RunE: func(cmd *cobra.Command, args []string) error {
return o.run(false)
}}
},
}

o.addFlags(cmd.Flags())
cmdutil.MarkFlagsRequired(cmd, []string{"name", "port"})
Expand All @@ -59,7 +60,8 @@ func ImportUpdateCmd() *cobra.Command {
Long: `Update an imported service that can be bounded to other peers`,
RunE: func(cmd *cobra.Command, args []string) error {
return o.run(true)
}}
},
}

o.addFlags(cmd.Flags())
cmdutil.MarkFlagsRequired(cmd, []string{"name", "port"})
Expand Down Expand Up @@ -92,7 +94,8 @@ func (o *importOptions) run(isUpdate bool) error {
Spec: api.ImportSpec{
Service: api.Endpoint{
Host: o.host,
Port: o.port},
Port: o.port,
},
},
})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controlplane/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func newClient(peer *store.Peer, tlsConfig *tls.Config) *client {
stopSignal: make(chan struct{}),
logger: logrus.WithFields(logrus.Fields{
"component": "peer-client",
"peer": peer}),
"peer": peer,
}),
}

go c.heartbeatMonitor()
Expand Down
2 changes: 1 addition & 1 deletion pkg/controlplane/eventmanager/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type ConnectionRequestAttr struct {
SrcService string
DstService string
Direction Direction
OtherPeer string //Optional: Would not be set if its an outgoing connection
OtherPeer string // Optional: Would not be set if its an outgoing connection
}

type ConnectionRequestResp struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controlplane/portmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func newPortManager() *portManager {

logger.WithFields(logrus.Fields{
"start": startPort,
"end": endPort},
"end": endPort,
},
).Info("Initialized.")

return &portManager{
Expand Down
3 changes: 2 additions & 1 deletion pkg/controlplane/xdsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ func makeEndpointsCluster(name string, endpoints []api.Endpoint, hostname string
}

func makeTCPProxyFilter(clusterName, statPrefix string,
tunnelingConfig *tcpproxy.TcpProxy_TunnelingConfig) (*listener.Filter, error) {
tunnelingConfig *tcpproxy.TcpProxy_TunnelingConfig,
) (*listener.Filter, error) {
tcpProxyConfig := &tcpproxy.TcpProxy{
StatPrefix: "tcp-proxy-" + statPrefix,
ClusterSpecifier: &tcpproxy.TcpProxy_Cluster{
Expand Down
3 changes: 2 additions & 1 deletion pkg/dataplane/client/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func newFetcher(ctx context.Context, conn *grpc.ClientConn, resourceType string,
if err != nil {
return nil, err
}
return &fetcher{client: client,
return &fetcher{
client: client,
resourceType: resourceType,
dataplane: dataplane,
logger: logrus.WithField("component", "fetcher.xds.client"),
Expand Down
6 changes: 4 additions & 2 deletions pkg/dataplane/client/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ func (x *XDSClient) Run() error {

// NewXDSClient returns am xDS client which can fetch clusters and listeners from the controlplane.
func NewXDSClient(dataplane *server.Dataplane, controlplaneTarget string, tlsConfig *tls.Config) *XDSClient {
return &XDSClient{dataplane: dataplane,
return &XDSClient{
dataplane: dataplane,
controlplaneTarget: controlplaneTarget,
tlsConfig: tlsConfig,
errors: make(map[string]error),
logger: logrus.WithField("component", "xds.client"),
clustersReady: make(chan bool, 1)}
clustersReady: make(chan bool, 1),
}
}
7 changes: 4 additions & 3 deletions pkg/dataplane/server/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ func (f *forwarder) run() {
}

func newForwarder(workloadConn net.Conn, peerConn net.Conn) *forwarder {
return &forwarder{workloadConn: workloadConn,
peerConn: peerConn,
logger: logrus.WithField("component", "dataplane.forwarder"),
return &forwarder{
workloadConn: workloadConn,
peerConn: peerConn,
logger: logrus.WithField("component", "dataplane.forwarder"),
}
}
6 changes: 4 additions & 2 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (
event "github.com/clusterlink-net/clusterlink/pkg/controlplane/eventmanager"
)

var mlog = logrus.WithField("component", "Metrics")
var MyMetricsManager Metrics
var (
mlog = logrus.WithField("component", "Metrics")
MyMetricsManager Metrics
)

type Metrics struct {
ConnectionFlow map[string]*event.ConnectionStatusAttr
Expand Down
3 changes: 2 additions & 1 deletion pkg/platform/k8s/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (p *Platform) UpdateExternalService(name, host, externalName string) {
// DeleteService deletes a service.
func (p *Platform) DeleteService(name, host string) {
serviceSpec := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: host, Namespace: p.namespace}}
ObjectMeta: metav1.ObjectMeta{Name: host, Namespace: p.namespace},
}

p.logger.Infof("Deleting K8s service %s.", host)
go p.serviceReconciler.DeleteResource(name, serviceSpec)
Expand Down
3 changes: 1 addition & 2 deletions pkg/platform/unknown/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
package unknown

// Platform represents an unknown platform.
type Platform struct {
}
type Platform struct{}

// CreateService creates a service.
func (p *Platform) CreateService(_, _, _ string, _, _ uint16) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/policyengine/PolicyDispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func TestOutgoingConnectionRequests(t *testing.T) {
ph := policyengine.NewPolicyHandler()
simpleSelector2 := metav1.LabelSelector{MatchLabels: policytypes.WorkloadAttrs{
policyengine.ServiceNameLabel: svcName,
policyengine.GatewayNameLabel: peer2}}
policyengine.GatewayNameLabel: peer2,
}}
simpleWorkloadSet2 := policytypes.WorkloadSetOrSelector{WorkloadSelector: &simpleSelector2}
policy2 := policy
policy2.To = []policytypes.WorkloadSetOrSelector{simpleWorkloadSet2}
Expand Down
9 changes: 6 additions & 3 deletions pkg/policyengine/connectivitypdp/connectivity_pdp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ func TestPrivilegedVsRegular(t *testing.T) {
workloadSet := []policytypes.WorkloadSetOrSelector{trivialWorkloadSet}
trivialConnPol := policytypes.ConnectivityPolicy{
Name: "reg", Privileged: false, Action: policytypes.PolicyActionAllow,
From: workloadSet, To: workloadSet}
From: workloadSet, To: workloadSet,
}
trivialPrivConnPol := policytypes.ConnectivityPolicy{
Name: "priv", Privileged: true, Action: policytypes.PolicyActionDeny,
From: workloadSet, To: workloadSet}
From: workloadSet, To: workloadSet,
}

pdp := connectivitypdp.NewPDP()
dests := []policytypes.WorkloadAttrs{trivialLabel}
Expand Down Expand Up @@ -171,7 +173,8 @@ func TestBadSelector(t *testing.T) {
Name: "aBadPolicy",
Action: policytypes.PolicyActionAllow,
From: []policytypes.WorkloadSetOrSelector{badWorkloadSet},
To: []policytypes.WorkloadSetOrSelector{trivialWorkloadSet}}
To: []policytypes.WorkloadSetOrSelector{trivialWorkloadSet},
}
pdp := connectivitypdp.NewPDP()
err := pdp.AddOrUpdatePolicy(badSelectorPol)
require.NotNil(t, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/policyengine/policytypes/connectivity_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func TestMatching(t *testing.T) {
func TestDecide(t *testing.T) {
trivialConnPol := policytypes.ConnectivityPolicy{
Action: policytypes.PolicyActionDeny,
From: []policytypes.WorkloadSetOrSelector{trivialWorkloadSet}}
From: []policytypes.WorkloadSetOrSelector{trivialWorkloadSet},
}
decision, err := trivialConnPol.Decide(trivialLabel, trivialLabel)
require.Nil(t, err)
require.Equal(t, policytypes.PolicyDecisionUndecided, decision) // no match -> no decision
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/kv/bolt/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (s *Store) Close() error {
// Open a bolt store.
func Open(path string) (*Store, error) {
// open
db, err := bbolt.Open(path, 0666, nil)
db, err := bbolt.Open(path, 0o666, nil)
if err != nil {
return nil, fmt.Errorf("unable to open store: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (s *Server) GracefulStop() error {
func NewServer(name string, tlsConfig *tls.Config) Server {
logger := logrus.WithFields(logrus.Fields{
"component": "http-server",
"name": name})
"name": name,
})
logWriter := logger.WriterLevel(logrus.ErrorLevel)

router := chi.NewRouter()
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/jsonapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func NewClient(host string, port uint16, tlsConfig *tls.Config) *Client {
serverURL: serverURL,
logger: logrus.WithFields(logrus.Fields{
"component": "http-client",
"server-url": serverURL}),
"server-url": serverURL,
}),
}
}
Loading

0 comments on commit b751c70

Please sign in to comment.