Skip to content

Commit 34f5f98

Browse files
authored
fix gate issue (#1959)
1 parent ac77d5e commit 34f5f98

File tree

23 files changed

+72
-93
lines changed

23 files changed

+72
-93
lines changed

pkg/autohealing/cloudprovider/openstack/provider.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,11 @@ func (provider CloudProvider) waitForServerDetachVolumes(serverID string, timeou
253253
}
254254

255255
// FirstTimeRepair Handle the first time repair for a node
256-
// 1) If the node is the first time in error, reboot and uncordon it
257-
// 2) If the node is not the first time in error, check if the last reboot time is in provider.Config.RebuildDelayAfterReboot
258-
// That said, if the node has been found in broken status before but has been long time since then, the processed variable
259-
// will be kept as False, which means the node need to be rebuilt to fix it, otherwise it means the has been processed.
256+
// 1. If the node is the first time in error, reboot and uncordon it
257+
// 2. If the node is not the first time in error, check if the last reboot time is in provider.Config.RebuildDelayAfterReboot
258+
// That said, if the node has been found in broken status before but has been long time since then, the processed variable
259+
// will be kept as False, which means the node need to be rebuilt to fix it, otherwise it means the has been processed.
260+
//
260261
// The bool type return value means that if the node has been processed from a first time repair PoV
261262
func (provider CloudProvider) firstTimeRepair(n healthcheck.NodeInfo, serverID string, firstTimeRebootNodes map[string]healthcheck.NodeInfo) (bool, error) {
262263
var firstTimeUnhealthy = true
@@ -313,12 +314,14 @@ func (provider CloudProvider) firstTimeRepair(n healthcheck.NodeInfo, serverID s
313314
}
314315

315316
// Repair For master nodes: detach etcd and docker volumes, find the root
316-
// volume, then shutdown the VM, marks the both the VM and the root
317-
// volume (heat resource) as "unhealthy" then trigger Heat stack update
318-
// in order to rebuild the node. The information this function needs:
319-
// - Nova VM ID
320-
// - Root volume ID
321-
// - Heat stack ID and resource ID.
317+
//
318+
// volume, then shutdown the VM, marks the both the VM and the root
319+
// volume (heat resource) as "unhealthy" then trigger Heat stack update
320+
// in order to rebuild the node. The information this function needs:
321+
// - Nova VM ID
322+
// - Root volume ID
323+
// - Heat stack ID and resource ID.
324+
//
322325
// For worker nodes: Call Magnum resize API directly.
323326
func (provider CloudProvider) Repair(nodes []healthcheck.NodeInfo) error {
324327
if len(nodes) == 0 {

pkg/autohealing/healthcheck/plugin_endpoint.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package healthcheck
1919
import (
2020
"crypto/tls"
2121
"fmt"
22-
"io/ioutil"
2322
"net/http"
23+
"os"
2424
"strings"
2525
"time"
2626

@@ -157,7 +157,7 @@ func (check *EndpointCheck) Check(node NodeInfo, controller NodeController) bool
157157

158158
if check.RequireToken {
159159
if check.Token == "" {
160-
b, err := ioutil.ReadFile(TokenPath)
160+
b, err := os.ReadFile(TokenPath)
161161
if err != nil {
162162
log.Warningf("Node %s, failed to get token from %s, skip the check", nodeName, TokenPath)
163163
return true

pkg/csi/cinder/driver.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ var (
4848
Version = "2.0.0"
4949
)
5050

51-
//revive:disable:exported
5251
// Deprecated: use Driver instead
52+
//
53+
//revive:disable:exported
5354
type CinderDriver = Driver
5455

5556
//revive:enable:exported

pkg/csi/cinder/nodeserver_test.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package cinder
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423
"testing"
@@ -379,13 +378,10 @@ func TestNodeGetVolumeStatsBlock(t *testing.T) {
379378
mmock.ExpectedCalls = nil
380379

381380
// setup for test
382-
tempDir, err := ioutil.TempDir("", "cpo-test")
383-
if err != nil {
384-
t.Fatalf("Failed to set up temp dir: %v", err)
385-
}
386-
defer os.RemoveAll(tempDir)
381+
tempDir := os.TempDir()
382+
defer os.Remove(tempDir)
387383
volumePath := filepath.Join(tempDir, FakeTargetPath)
388-
err = os.MkdirAll(volumePath, 0750)
384+
err := os.MkdirAll(volumePath, 0750)
389385
if err != nil {
390386
t.Fatalf("Failed to set up volumepath: %v", err)
391387
}
@@ -417,13 +413,10 @@ func TestNodeGetVolumeStatsFs(t *testing.T) {
417413
mmock.ExpectedCalls = nil
418414

419415
// setup for test
420-
tempDir, err := ioutil.TempDir("", "cpo-test")
421-
if err != nil {
422-
t.Fatalf("Failed to set up temp dir: %v", err)
423-
}
424-
defer os.RemoveAll(tempDir)
416+
tempDir := os.TempDir()
417+
defer os.Remove(tempDir)
425418
volumePath := filepath.Join(tempDir, FakeTargetPath)
426-
err = os.MkdirAll(volumePath, 0750)
419+
err := os.MkdirAll(volumePath, 0750)
427420
if err != nil {
428421
t.Fatalf("Failed to set up volumepath: %v", err)
429422
}

pkg/csi/cinder/openstack/openstack_snapshots.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (os *OpenStack) DeleteSnapshot(snapID string) error {
142142
return err
143143
}
144144

145-
//GetSnapshotByID returns snapshot details by id
145+
// GetSnapshotByID returns snapshot details by id
146146
func (os *OpenStack) GetSnapshotByID(snapshotID string) (*snapshots.Snapshot, error) {
147147
s, err := snapshots.Get(os.blockstorage, snapshotID).Extract()
148148
if err != nil {

pkg/csi/cinder/openstack/openstack_volumes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (os *OpenStack) WaitDiskAttached(instanceID string, volumeID string) error
223223
return err
224224
}
225225

226-
//WaitVolumeTargetStatus waits for volume to be in target state
226+
// WaitVolumeTargetStatus waits for volume to be in target state
227227
func (os *OpenStack) WaitVolumeTargetStatus(volumeID string, tStatus []string) error {
228228
backoff := wait.Backoff{
229229
Duration: operationFinishInitDelay,
@@ -358,7 +358,7 @@ func (os *OpenStack) ExpandVolume(volumeID string, status string, newSize int) e
358358
return fmt.Errorf("volume cannot be resized, when status is %s", status)
359359
}
360360

361-
//GetMaxVolLimit returns max vol limit
361+
// GetMaxVolLimit returns max vol limit
362362
func (os *OpenStack) GetMaxVolLimit() int64 {
363363
if os.bsOpts.NodeVolumeAttachLimit > 0 && os.bsOpts.NodeVolumeAttachLimit <= 256 {
364364
return os.bsOpts.NodeVolumeAttachLimit

pkg/csi/manila/runtimeconfig/runtimeconfig.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package runtimeconfig
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
2221
"os"
2322
)
2423

@@ -34,7 +33,7 @@ type RuntimeConfig struct {
3433
func Get() (*RuntimeConfig, error) {
3534
// File contents are deliberately not cached
3635
// as they may change over time.
37-
data, err := ioutil.ReadFile(RuntimeConfigFilename)
36+
data, err := os.ReadFile(RuntimeConfigFilename)
3837
if err != nil {
3938
if os.IsNotExist(err) {
4039
return nil, nil

pkg/csi/manila/validator/validator.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ import (
2828
// By default, the input data has to contain a value for each struct field.
2929
//
3030
// Available tags:
31-
// * name:"FIELD-NAME" : key of the value in the input map
32-
// * value: modifies value requirements:
33-
// value:"required" : field is required
34-
// value:"optional" : field is optional
35-
// value:"requiredIf:FIELD-NAME=REGEXP-PATTERN" : field is required if the value of FIELD-NAME matches REGEXP-PATTERN
36-
// value:"optionalIf:FIELD-NAME=REGEXP-PATTERN" : field is optional if the value of FIELD-NAME matches REGEXP-PATTERN
37-
// value:"default:VALUE" : field value defaults to VALUE
38-
// * dependsOn:"FIELD-NAMES|,..." : if this field is not empty, the specified fields are required to be present
39-
// operator ',' acts as AND
40-
// operator '|' acts as XOR
41-
// e.g.: dependsOn:"f1|f2|f3,f4,f5" : if this field is not empty, exactly one of {f1,f2,f3} is required to be present,
42-
// and f4 and f5 is required to be present
43-
// * precludes:"FIELD-NAMES,..." : if this field is not empty, all specified fields are required to be empty
44-
// * matches:"REGEXP-PATTERN" : if this field is not empty, it's required to match REGEXP-PATTERN
31+
// - name:"FIELD-NAME" : key of the value in the input map
32+
// - value: modifies value requirements:
33+
// value:"required" : field is required
34+
// value:"optional" : field is optional
35+
// value:"requiredIf:FIELD-NAME=REGEXP-PATTERN" : field is required if the value of FIELD-NAME matches REGEXP-PATTERN
36+
// value:"optionalIf:FIELD-NAME=REGEXP-PATTERN" : field is optional if the value of FIELD-NAME matches REGEXP-PATTERN
37+
// value:"default:VALUE" : field value defaults to VALUE
38+
// - dependsOn:"FIELD-NAMES|,..." : if this field is not empty, the specified fields are required to be present
39+
// operator ',' acts as AND
40+
// operator '|' acts as XOR
41+
// e.g.: dependsOn:"f1|f2|f3,f4,f5" : if this field is not empty, exactly one of {f1,f2,f3} is required to be present,
42+
// and f4 and f5 is required to be present
43+
// - precludes:"FIELD-NAMES,..." : if this field is not empty, all specified fields are required to be empty
44+
// - matches:"REGEXP-PATTERN" : if this field is not empty, it's required to match REGEXP-PATTERN
4545
type Validator struct {
4646
t reflect.Type
4747

pkg/identity/keystone/sync.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"io/ioutil"
23+
"os"
2424
"regexp"
2525
"strings"
2626
"sync"
@@ -134,7 +134,7 @@ func newSyncConfig() syncConfig {
134134
func newSyncConfigFromFile(path string) (*syncConfig, error) {
135135
sc := newSyncConfig()
136136

137-
yamlFile, err := ioutil.ReadFile(path)
137+
yamlFile, err := os.ReadFile(path)
138138
if err != nil {
139139
klog.Errorf("yamlFile get err #%v ", err)
140140
return nil, err

pkg/identity/keystone/token_getter.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package keystone
1919
import (
2020
"crypto/tls"
2121
"fmt"
22+
"os"
23+
2224
"github.com/gophercloud/gophercloud"
2325
"github.com/gophercloud/gophercloud/openstack"
2426
tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens"
2527
"github.com/gophercloud/utils/client"
26-
"io/ioutil"
2728
certutil "k8s.io/client-go/util/cert"
2829
osClient "k8s.io/cloud-provider-openstack/pkg/client"
2930
"k8s.io/cloud-provider-openstack/pkg/version"
@@ -57,13 +58,13 @@ func GetToken(options Options) (*tokens3.Token, error) {
5758
provider.UserAgent = userAgent
5859

5960
if options.ClientCertPath != "" && options.ClientKeyPath != "" {
60-
clientCert, err := ioutil.ReadFile(options.ClientCertPath)
61+
clientCert, err := os.ReadFile(options.ClientCertPath)
6162
if err != nil {
6263
msg := fmt.Errorf("failed: Cannot read cert file: %v", err)
6364
return token, msg
6465
}
6566

66-
clientKey, err := ioutil.ReadFile(options.ClientKeyPath)
67+
clientKey, err := os.ReadFile(options.ClientKeyPath)
6768
if err != nil {
6869
msg := fmt.Errorf("failed: Cannot read key file: %v", err)
6970
return token, msg

pkg/identity/keystone/token_getter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package keystone
1616
import (
1717
"encoding/json"
1818
"fmt"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"testing"
2222

@@ -46,7 +46,7 @@ func TestTokenGetter(t *testing.T) {
4646
}
4747
}
4848
var x AuthRequest
49-
body, _ := ioutil.ReadAll(r.Body)
49+
body, _ := io.ReadAll(r.Body)
5050
_ = json.Unmarshal(body, &x)
5151
domainName := x.Auth.Identity.Password.User.Domain.Name
5252
userName := x.Auth.Identity.Password.User.Name

pkg/ingress/controller/controller.go

-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,6 @@ func privateKeyFromPEM(pemData []byte) (crypto.PrivateKey, error) {
10331033

10341034
// parsePEMBundle parses a certificate bundle from top to bottom and returns
10351035
// a slice of x509 certificates. This function will error if no certificates are found.
1036-
//
10371036
func parsePEMBundle(bundle []byte) ([]*x509.Certificate, error) {
10381037
var certificates []*x509.Certificate
10391038
var certDERBlock *pem.Block

pkg/kms/barbican/barbican.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type KMSOpts struct {
1111
KeyID string `gcfg:"key-id"`
1212
}
1313

14-
//Config to read config options
14+
// Config to read config options
1515
type Config struct {
1616
Global client.AuthOpts
1717
KeyManager KMSOpts

pkg/openstack/instances.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package openstack
1919
import (
2020
"context"
2121
"fmt"
22-
"io/ioutil"
2322
"net"
23+
"os"
2424
"regexp"
2525
"sort"
2626
"strings"
@@ -414,7 +414,7 @@ func readInstanceID(searchOrder string) (string, error) {
414414

415415
// Try to find instance ID on the local filesystem (created by cloud-init)
416416
const instanceIDFile = "/var/lib/cloud/data/instance-id"
417-
idBytes, err := ioutil.ReadFile(instanceIDFile)
417+
idBytes, err := os.ReadFile(instanceIDFile)
418418
if err == nil {
419419
instanceID := string(idBytes)
420420
instanceID = strings.TrimSpace(instanceID)

pkg/openstack/loadbalancer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ func nodeAddressForLB(node *corev1.Node, preferredIPFamily corev1.IPFamily) (str
759759
return "", cpoerrors.ErrNoAddressFound
760760
}
761761

762-
//getStringFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's value or a specified defaultSetting
762+
// getStringFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's value or a specified defaultSetting
763763
func getStringFromServiceAnnotation(service *corev1.Service, annotationKey string, defaultSetting string) string {
764764
klog.V(4).Infof("getStringFromServiceAnnotation(%s/%s, %v, %v)", service.Namespace, service.Name, annotationKey, defaultSetting)
765765
if annotationValue, ok := service.Annotations[annotationKey]; ok {
@@ -776,7 +776,7 @@ func getStringFromServiceAnnotation(service *corev1.Service, annotationKey strin
776776
return defaultSetting
777777
}
778778

779-
//getIntFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's integer value or a specified defaultSetting
779+
// getIntFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's integer value or a specified defaultSetting
780780
func getIntFromServiceAnnotation(service *corev1.Service, annotationKey string, defaultSetting int) int {
781781
klog.V(4).Infof("getIntFromServiceAnnotation(%s/%s, %v, %v)", service.Namespace, service.Name, annotationKey, defaultSetting)
782782
if annotationValue, ok := service.Annotations[annotationKey]; ok {
@@ -793,7 +793,7 @@ func getIntFromServiceAnnotation(service *corev1.Service, annotationKey string,
793793
return defaultSetting
794794
}
795795

796-
//getBoolFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's boolean value or a specified defaultSetting
796+
// getBoolFromServiceAnnotation searches a given v1.Service for a specific annotationKey and either returns the annotation's boolean value or a specified defaultSetting
797797
func getBoolFromServiceAnnotation(service *corev1.Service, annotationKey string, defaultSetting bool) bool {
798798
klog.V(4).Infof("getBoolFromServiceAnnotation(%s/%s, %v, %v)", service.Namespace, service.Name, annotationKey, defaultSetting)
799799
if annotationValue, ok := service.Annotations[annotationKey]; ok {
@@ -1202,7 +1202,7 @@ func (lbaas *LbaasV2) ensureOctaviaHealthMonitor(lbID string, name string, pool
12021202
return nil
12031203
}
12041204

1205-
//buildMonitorCreateOpts returns a v2monitors.CreateOpts without PoolID for consumption of both, fully popuplated Loadbalancers and Monitors.
1205+
// buildMonitorCreateOpts returns a v2monitors.CreateOpts without PoolID for consumption of both, fully popuplated Loadbalancers and Monitors.
12061206
func (lbaas *LbaasV2) buildMonitorCreateOpts(svcConf *serviceConfig, port corev1.ServicePort) v2monitors.CreateOpts {
12071207
monitorProtocol := string(port.Protocol)
12081208
if port.Protocol == corev1.ProtocolUDP {
@@ -1316,7 +1316,7 @@ func (lbaas *LbaasV2) buildPoolCreateOpt(listenerProtocol string, service *corev
13161316
}
13171317
}
13181318

1319-
//buildBatchUpdateMemberOpts returns v2pools.BatchUpdateMemberOpts array for Services and Nodes alongside a list of member names
1319+
// buildBatchUpdateMemberOpts returns v2pools.BatchUpdateMemberOpts array for Services and Nodes alongside a list of member names
13201320
func (lbaas *LbaasV2) buildBatchUpdateMemberOpts(port corev1.ServicePort, nodes []*corev1.Node, svcConf *serviceConfig) ([]v2pools.BatchUpdateMemberOpts, sets.String, error) {
13211321
var members []v2pools.BatchUpdateMemberOpts
13221322
newMembers := sets.NewString()
@@ -1441,7 +1441,7 @@ func (lbaas *LbaasV2) ensureOctaviaListener(lbID string, name string, curListene
14411441
return listener, nil
14421442
}
14431443

1444-
//buildListenerCreateOpt returns listeners.CreateOpts for a specific Service port and configuration
1444+
// buildListenerCreateOpt returns listeners.CreateOpts for a specific Service port and configuration
14451445
func (lbaas *LbaasV2) buildListenerCreateOpt(port corev1.ServicePort, svcConf *serviceConfig) listeners.CreateOpts {
14461446
listenerProtocol := listeners.Protocol(port.Protocol)
14471447

pkg/openstack/openstack_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package openstack
1919
import (
2020
"context"
2121
"fmt"
22-
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524
"reflect"
@@ -171,7 +170,7 @@ clouds:
171170
identity_api_version: 3
172171
`
173172
data := []byte(cloud)
174-
err = ioutil.WriteFile(cloudFile, data, 0644)
173+
err = os.WriteFile(cloudFile, data, 0644)
175174
if err != nil {
176175
t.Error(err)
177176
}

pkg/util/blockdevice/blockdevice_linux.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package blockdevice
1919
import (
2020
"fmt"
2121
"io"
22-
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524
"strings"
@@ -108,7 +107,7 @@ func RescanBlockDeviceGeometry(devicePath string, deviceMountPath string, newSiz
108107

109108
klog.V(3).Infof("Resolved block device path from %q to %q", devicePath, blockDeviceRescanPath)
110109
klog.V(4).Infof("Rescanning %q block device geometry", devicePath)
111-
err = ioutil.WriteFile(blockDeviceRescanPath, []byte{'1'}, 0666)
110+
err = os.WriteFile(blockDeviceRescanPath, []byte{'1'}, 0666)
112111
if err != nil {
113112
klog.Errorf("Error rescanning new block device geometry: %v", err)
114113
// no need to run checkBlockDeviceSize second time here, return the saved error

pkg/util/errors/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var ErrNoAddressFound = errors.New("no address found for host")
3636
// IPv6 support is disabled by config
3737
var ErrIPv6SupportDisabled = errors.New("IPv6 support is disabled")
3838

39-
//ErrNoRouterID is used when router-id is not set
39+
// ErrNoRouterID is used when router-id is not set
4040
var ErrNoRouterID = errors.New("router-id not set in cloud provider config")
4141

4242
func IsNotFound(err error) bool {

0 commit comments

Comments
 (0)