Skip to content

Commit 286d666

Browse files
authored
Resolve nilnil and nilaway issues (#447)
* addressed nilaway issues * addressed nilnil issues * added nolint:nilnil and nolint:nilaway where needed * added changes to error messages
1 parent d75d8ce commit 286d666

24 files changed

+83
-22
lines changed

cloud/config/config.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,30 @@ func getConfigFromDir(path string) (*AuthConfig, error) {
146146
}
147147

148148
func NewConfigurationProvider(cfg *AuthConfig) (common.ConfigurationProvider, error) {
149+
if cfg == nil {
150+
return nil, errors.New("auth config must not be nil")
151+
}
149152
if cfg.UseInstancePrincipals {
150153
return auth.InstancePrincipalConfigurationProvider()
151154
} else {
152155
return NewConfigurationProviderWithUserPrincipal(cfg)
153156
}
154157
}
155158

159+
// nolint:nilnil
156160
func NewConfigurationProviderWithUserPrincipal(cfg *AuthConfig) (common.ConfigurationProvider, error) {
157161
var conf common.ConfigurationProvider
158-
if cfg != nil {
159-
conf = common.NewRawConfigurationProvider(
160-
cfg.TenancyID,
161-
cfg.UserID,
162-
cfg.Region,
163-
cfg.Fingerprint,
164-
cfg.PrivateKey,
165-
common.String(cfg.Passphrase))
166-
return conf, nil
167-
}
168-
return nil, nil
162+
if cfg == nil {
163+
return nil, errors.New("cfg cannot be nil")
164+
}
165+
conf = common.NewRawConfigurationProvider(
166+
cfg.TenancyID,
167+
cfg.UserID,
168+
cfg.Region,
169+
cfg.Fingerprint,
170+
cfg.PrivateKey,
171+
common.String(cfg.Passphrase))
172+
return conf, nil
169173
}
170174

171175
func ReadFile(path string, key string) (string, error) {

cloud/ociutil/ociutil.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ var ErrNotFound = errors.New("not found")
4949

5050
// IsNotFound returns true if the given error indicates that a resource could
5151
// not be found.
52+
// nolint:nilaway // We don't need to check if serviceErr is nil, because once ok is true,
53+
// serviceErr is non-nil and will not have any issue in accesing GetHTTPStatusCode() field
5254
func IsNotFound(err error) bool {
5355
if err == nil {
5456
return false

cloud/scope/clients.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ func NewClientProvider(params ClientProviderParams) (*ClientProvider, error) {
101101
}
102102

103103
// GetAuthProvider returns the client provider auth config
104+
// nolint:nilaway
104105
func (c *ClientProvider) GetAuthProvider() common.ConfigurationProvider {
105106
return c.ociAuthConfigProvider
106107
}
107108

108109
// GetOrBuildClient if the OCIClients exist for the region they are returned, if not clients will build them
109110
func (c *ClientProvider) GetOrBuildClient(region string) (OCIClients, error) {
111+
if c == nil || c.ociClients == nil {
112+
return OCIClients{}, errors.New("Client provider is not initialized")
113+
}
110114
if len(region) <= 0 {
111115
return OCIClients{}, errors.New("ClientProvider.GetOrBuildClient region can not be empty")
112116
}

cloud/scope/clients_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestClients_NewClientProviderWithClientOverrides(t *testing.T) {
8383
t.Errorf("Expected clientProvider:%v to equal nil", clientProvider)
8484
}
8585

86-
if !reflect.DeepEqual(clientProvider.ociClientOverrides, clientOverrides) {
86+
if clientProvider != nil && !reflect.DeepEqual(clientProvider.ociClientOverrides, clientOverrides) {
8787
t.Errorf("clientProvider.ociClientOverrides: %v doesn't equal clientOverrides: %v", clientProvider.ociClientOverrides, clientOverrides)
8888
}
8989
}
@@ -124,7 +124,7 @@ func TestClients_NewClientProviderWithMissingOverrides(t *testing.T) {
124124
t.Errorf("Expected clientProvider:%v to equal nil", clientProvider)
125125
}
126126

127-
if !reflect.DeepEqual(clientProvider.ociClientOverrides, clientOverrides) {
127+
if clientProvider != nil && !reflect.DeepEqual(clientProvider.ociClientOverrides, clientOverrides) {
128128
t.Errorf("clientProvider.ociClientOverrides: %v doesn't equal clientOverrides: %v", clientProvider.ociClientOverrides, clientOverrides)
129129
}
130130
}

cloud/scope/drg_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (s *ClusterScope) ReconcileDRG(ctx context.Context) error {
6464
// 1. the OCICluster's spec Drg
6565
//
6666
// 2. Listing the Drgs for the Compartment (by ID) and filtering by tag
67+
// nolint:nilnil
6768
func (s *ClusterScope) GetDRG(ctx context.Context) (*core.Drg, error) {
6869
drgId := s.getDRG().ID
6970
if drgId != nil {

cloud/scope/drg_rpc_attachment_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func (s *ClusterScope) createRPC(ctx context.Context, drgId *string, displayName
158158
return &response.RemotePeeringConnection, nil
159159
}
160160

161+
// nolint:nilnil
161162
func (s *ClusterScope) lookupRPC(ctx context.Context, drgId *string, rpcId *string, vcnClient vcn.Client) (*core.RemotePeeringConnection, error) {
162163
if rpcId != nil {
163164
attachment, err := s.getRPC(ctx, rpcId, vcnClient)

cloud/scope/drg_vcn_attachment_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (s *ClusterScope) ReconcileDRGVCNAttachment(ctx context.Context) error {
6363
return nil
6464
}
6565

66+
// nolint:nilnil
6667
func (s *ClusterScope) GetDRGAttachment(ctx context.Context) (*core.DrgAttachment, error) {
6768
if s.getDRG().VcnAttachmentId != nil {
6869
response, err := s.VCNClient.GetDrgAttachment(ctx, core.GetDrgAttachmentRequest{

cloud/scope/internet_gateway_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (s *ClusterScope) ReconcileInternetGateway(ctx context.Context) error {
5858
// 1. the OCICluster's spec InternetGatewayId
5959
//
6060
// 2. Listing the Internet Gateways for the Compartment (by ID) and filtering by tag
61+
// nolint:nilnil
6162
func (s *ClusterScope) GetInternetGateway(ctx context.Context) (*core.InternetGateway, error) {
6263
gwId := s.OCIClusterAccessor.GetNetworkSpec().Vcn.InternetGateway.Id
6364
if gwId != nil {

cloud/scope/load_balancer_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func (s *ClusterScope) IsLBEqual(actual *loadbalancer.LoadBalancer, desired infr
259259
// 1. the OCICluster's spec LoadBalancerId
260260
//
261261
// 2. Listing the LoadBalancers for the Compartment (by ID) and DisplayName then filtering by tag
262+
// nolint:nilnil
262263
func (s *ClusterScope) GetLoadBalancers(ctx context.Context) (*loadbalancer.LoadBalancer, error) {
263264
lbOcid := s.OCIClusterAccessor.GetNetworkSpec().APIServerLB.LoadBalancerId
264265
if lbOcid != nil {

cloud/scope/machine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func (m *MachineScope) getMachineFromOCID(ctx context.Context, instanceID *strin
348348

349349
// GetMachineByDisplayName returns the machine from the compartment if there is a matching DisplayName,
350350
// and it was created by the cluster
351+
// nolint:nilnil
351352
func (m *MachineScope) GetMachineByDisplayName(ctx context.Context, name string) (*core.Instance, error) {
352353
var page *string
353354
for {

0 commit comments

Comments
 (0)