Skip to content

Commit

Permalink
Address return consistency
Browse files Browse the repository at this point in the history
add argocd applications updates
  • Loading branch information
sebrandon1 committed Jan 20, 2025
1 parent 3234969 commit 0d5077b
Show file tree
Hide file tree
Showing 36 changed files with 118 additions and 102 deletions.
8 changes: 2 additions & 6 deletions pkg/assisted/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
nonExistentMsg = "Cannot update non-existent agent"
nonExistentMsg = "cannot update non-existent agent"
)

// agentBuilder provides struct for the agent object containing connection to
Expand Down Expand Up @@ -300,11 +300,7 @@ func (builder *agentBuilder) Update() (*agentBuilder, error) {
glog.V(100).Infof("agent %s in namespace %s does not exist",
builder.Definition.Name, builder.Definition.Namespace)

builder.errorMsg = nonExistentMsg
}

if builder.errorMsg != "" {
return nil, fmt.Errorf(builder.errorMsg)
return builder, fmt.Errorf(nonExistentMsg)
}

err := builder.apiClient.Update(context.TODO(), builder.Definition)
Expand Down
1 change: 0 additions & 1 deletion pkg/assisted/agentclusterinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ func (builder *AgentClusterInstallBuilder) Update(force bool) (*AgentClusterInst

err = builder.DeleteAndWait(time.Second * 10)
builder.Definition.ResourceVersion = ""
// fmt.Printf("agentclusterinstall exists: %v\n", builder.Exists())

if err != nil {
glog.V(100).Infof(
Expand Down
14 changes: 6 additions & 8 deletions pkg/assisted/agentserviceconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ func (builder *AgentServiceConfigBuilder) WithMirrorRegistryRef(configMapName st
glog.V(100).Infof("The configMapName is empty")

builder.errorMsg = "cannot add agentserviceconfig mirrorRegistryRef with empty configmap name"
}

if builder.errorMsg != "" {
return builder
}

Expand Down Expand Up @@ -263,7 +261,7 @@ func (builder *AgentServiceConfigBuilder) WaitUntilDeployed(timeout time.Duratio
if !builder.Exists() {
glog.V(100).Infof("The agentserviceconfig does not exist on the cluster")

return builder, fmt.Errorf("cannot wait for non-existent agentserviceconfig to be deployed")
return nil, fmt.Errorf("cannot wait for non-existent agentserviceconfig to be deployed")
}

// Polls every retryInterval to determine if agentserviceconfig is in desired state.
Expand Down Expand Up @@ -310,7 +308,7 @@ func PullAgentServiceConfig(apiClient *clients.Settings) (*AgentServiceConfigBui
return nil, fmt.Errorf("the apiClient is nil")
}

builder := AgentServiceConfigBuilder{
builder := &AgentServiceConfigBuilder{
apiClient: apiClient.Client,
Definition: &agentInstallV1Beta1.AgentServiceConfig{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -325,7 +323,7 @@ func PullAgentServiceConfig(apiClient *clients.Settings) (*AgentServiceConfigBui

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get fetches the defined agentserviceconfig from the cluster.
Expand Down Expand Up @@ -383,7 +381,7 @@ func (builder *AgentServiceConfigBuilder) Update(force bool) (*AgentServiceConfi
glog.V(100).Infof("agentserviceconfig %s does not exist",
builder.Definition.Name)

return builder, fmt.Errorf("cannot update non-existent agentserviceconfig")
return nil, fmt.Errorf("cannot update non-existent agentserviceconfig")
}

err := builder.apiClient.Update(context.TODO(), builder.Definition)
Expand Down Expand Up @@ -524,13 +522,13 @@ func (builder *AgentServiceConfigBuilder) validate() (bool, error) {
if builder.Definition == nil {
glog.V(100).Infof("The %s is undefined", resourceCRD)

builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD)
return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD))
}

if builder.apiClient == nil {
glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD)

builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD)
return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD)
}

if builder.errorMsg != "" {
Expand Down
6 changes: 1 addition & 5 deletions pkg/assisted/infraenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,7 @@ func (builder *InfraEnvBuilder) Update(force bool) (*InfraEnvBuilder, error) {
glog.V(100).Infof("infraenv %s in namespace %s does not exist",
builder.Definition.Name, builder.Definition.Namespace)

builder.errorMsg = "Cannot update non-existent infraenv"
}

if builder.errorMsg != "" {
return nil, fmt.Errorf(builder.errorMsg)
return nil, fmt.Errorf("cannot update non-existent infraenv")
}

err := builder.apiClient.Update(context.TODO(), builder.Definition)
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Pull(apiClient *clients.Settings, name string) (*Builder, error) {
if name == "" {
glog.V(100).Info("The name of the Console is empty")

return builder, fmt.Errorf("console 'name' cannot be empty")
return nil, fmt.Errorf("console 'name' cannot be empty")
}

glog.V(100).Infof("Pulling cluster console %s", name)
Expand Down
4 changes: 3 additions & 1 deletion pkg/hive/clusterdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type ClusterDeploymentAdditionalOptions func(builder *ClusterDeploymentBuilder)

// NewABMClusterDeploymentBuilder creates a new instance of
// ClusterDeploymentBuilder with platform type set to agentBareMetal.
//
//nolint:funlen

Check failure on line 34 in pkg/hive/clusterdeployment.go

View workflow job for this annotation

GitHub Actions / lint

directive `//nolint:funlen` is unused for linter "funlen" (nolintlint)
func NewABMClusterDeploymentBuilder(
apiClient *clients.Settings,
name string,
Expand Down Expand Up @@ -135,7 +137,7 @@ func NewClusterDeploymentByInstallRefBuilder(
if clusterInstallRef.Name == "" {
glog.V(100).Infof("The clusterInstallRef name of the clusterdeployment is empty")

builder.errorMsg = "clusterdeployment 'clusterInstallRef.name' cannot be empty"
builder.errorMsg = "clusterdeployment 'clusterInstallRef' cannot be empty"

return builder
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/hive/clusterimageset.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ func (builder *ClusterImageSetBuilder) validate() (bool, error) {
if builder.Definition == nil {
glog.V(100).Infof("The %s is undefined", resourceCRD)

builder.errorMsg = msg.UndefinedCrdObjectErrString(resourceCRD)
return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD))
}

if builder.apiClient == nil {
glog.V(100).Infof("The %s builder apiclient is nil", resourceCRD)

builder.errorMsg = fmt.Sprintf("%s builder cannot have nil apiClient", resourceCRD)
return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD)
}

if builder.errorMsg != "" {
Expand Down
10 changes: 5 additions & 5 deletions pkg/icsp/icsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ func NewICSPBuilder(apiClient *clients.Settings, name, source string, mirrors []
if name == "" {
glog.V(100).Infof("The name of the ImageContentSourcePolicy is empty")

icspBuilder.errorMsg = "imageContentSourcePolicy 'name' cannot be empty"
icspBuilder.errorMsg = "ImageContentSourcePolicy 'name' cannot be empty"

return icspBuilder
}

if source == "" {
glog.V(100).Infof("The Source of the ImageContentSourcePolicy is empty")

icspBuilder.errorMsg = "imageContentSourcePolicy 'source' cannot be empty"
icspBuilder.errorMsg = "ImageContentSourcePolicy 'source' cannot be empty"

return icspBuilder
}

if len(mirrors) == 0 {
glog.V(100).Infof("The mirrors of the ImageContentSourcePolicy are empty")

icspBuilder.errorMsg = "imageContentSourcePolicy 'mirrors' cannot be empty"
icspBuilder.errorMsg = "ImageContentSourcePolicy 'mirrors' cannot be empty"

return icspBuilder
}
Expand Down Expand Up @@ -254,15 +254,15 @@ func (builder *ICSPBuilder) WithRepositoryDigestMirror(source string, mirrors []
if source == "" {
glog.V(100).Infof("The source is empty")

builder.errorMsg = "imageContentSourcePolicy 'source' cannot be empty"
builder.errorMsg = "'source' cannot be empty"

return builder
}

if len(mirrors) == 0 {
glog.V(100).Infof("Mirrors is empty")

builder.errorMsg = "imageContentSourcePolicy 'mirrors' cannot be empty"
builder.errorMsg = "'mirrors' cannot be empty"

return builder
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/lso/localvolumeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func PullLocalVolumeSet(apiClient *clients.Settings, name, nsname string) (*Loca
return nil, err
}

builder := LocalVolumeSetBuilder{
builder := &LocalVolumeSetBuilder{
apiClient: apiClient.Client,
Definition: &lsov1alpha1.LocalVolumeSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -123,7 +123,7 @@ func PullLocalVolumeSet(apiClient *clients.Settings, name, nsname string) (*Loca

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get fetches existing localVolumeSet from cluster.
Expand Down
2 changes: 1 addition & 1 deletion pkg/metallb/bgpadvertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (builder *BGPAdvertisementBuilder) Update(force bool) (*BGPAdvertisementBui
}
}

return builder, err
return builder, nil
}

// WithAggregationLength4 adds the specified AggregationLength to the BGPAdvertisement.
Expand Down
4 changes: 2 additions & 2 deletions pkg/metallb/bgppeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ func PullBGPPeer(apiClient *clients.Settings, name, nsname string) (*BGPPeerBuil
if name == "" {
glog.V(100).Infof("The name of the bgppeer is empty")

return nil, fmt.Errorf("bgppeer 'name' cannot be empty")
return nil, fmt.Errorf("bgppeer object name cannot be empty")
}

if nsname == "" {
glog.V(100).Infof("The namespace of the bgppeer is empty")

return nil, fmt.Errorf("bgppeer 'namespace' cannot be empty")
return nil, fmt.Errorf("bgppeer object namespace cannot be empty")
}

if !builder.Exists() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/metallb/l2advertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (builder *L2AdvertisementBuilder) Update(force bool) (*L2AdvertisementBuild
}
}

return builder, err
return builder, nil
}

// WithNodeSelector adds the specified NodeSelectors to the L2Advertisement.
Expand Down
2 changes: 1 addition & 1 deletion pkg/nad/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (builder *Builder) GetString() (string, error) {
return "", err
}

return string(nadByte), err
return string(nadByte), nil
}

// fillConfigureString adds a configuration string to builder definition specs configuration if needed.
Expand Down
3 changes: 2 additions & 1 deletion pkg/networkpolicy/multinetegressrule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func TestEgressWithPeerPodSelector(t *testing.T) {
assert.Equal(t, builder.definition.To[0].PodSelector.MatchLabels["app"], "nginx")

builder = NewEgressRuleBuilder()

//nolint:goconst
builder.errorMsg = "error"

Expand Down Expand Up @@ -210,6 +209,7 @@ func TestEgressWithPeerPodSelectorAndCIDR(t *testing.T) {
builder = NewEgressRuleBuilder()

Check failure on line 209 in pkg/networkpolicy/multinetegressrule_test.go

View workflow job for this annotation

GitHub Actions / lint

SA4006: this value of `builder` is never used (staticcheck)

// Test invalid CIDR
builder = NewEgressRuleBuilder()
builder.WithPeerPodSelectorAndCIDR(metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "nginx",
Expand All @@ -221,6 +221,7 @@ func TestEgressWithPeerPodSelectorAndCIDR(t *testing.T) {
builder = NewEgressRuleBuilder()

Check failure on line 221 in pkg/networkpolicy/multinetegressrule_test.go

View workflow job for this annotation

GitHub Actions / lint

SA4006: this value of `builder` is never used (staticcheck)

// Test with exception
builder = NewEgressRuleBuilder()
builder.WithPeerPodSelectorAndCIDR(metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "nginx",
Expand Down
12 changes: 0 additions & 12 deletions pkg/networkpolicy/multinetingressrule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ func TestIngressWithPeerPodSelector(t *testing.T) {

assert.Len(t, builder.definition.From, 1)
assert.Equal(t, builder.definition.From[0].PodSelector.MatchLabels["app"], "nginx")

builder = NewIngressRuleBuilder()

builder.errorMsg = "error"

builder.WithPeerPodSelector(metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "nginx",
},
})

assert.Len(t, builder.definition.From, 0)
}

func TestIngressWithPeerNamespaceSelector(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkpolicy/multinetworkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func PullMultiNetworkPolicy(apiClient *clients.Settings, name, nsname string) (*
return nil, err
}

builder := MultiNetworkPolicyBuilder{
builder := &MultiNetworkPolicyBuilder{
apiClient: apiClient.Client,
Definition: &v1beta1.MultiNetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -236,7 +236,7 @@ func PullMultiNetworkPolicy(apiClient *clients.Settings, name, nsname string) (*

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get returns MultiNetworkPolicy object if found.
Expand Down
8 changes: 6 additions & 2 deletions pkg/nfd/nodefeaturediscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func NewBuilderFromObjectString(apiClient *clients.Settings, almExample string)
return nil
}

glog.V(100).Infof(
"Initializing Builder definition to NodeFeatureDiscovery object")

builder := &Builder{
apiClient: apiClient,
}
Expand All @@ -69,7 +72,8 @@ func NewBuilderFromObjectString(apiClient *clients.Settings, almExample string)
if builder.Definition == nil {
glog.V(100).Infof("The NodeFeatureDiscovery object definition is nil")

builder.errorMsg = "nodeFeatureDiscovery definition is nil"
//nolint:lll
builder.errorMsg = "Error initializing NodeFeatureDiscovery from alm-examples: invalid character 'i' looking for beginning of object key string"

return builder
}
Expand Down Expand Up @@ -249,7 +253,7 @@ func (builder *Builder) Update(force bool) (*Builder, error) {
}
}

return builder, err
return builder, nil
}

// getNodeFeatureDiscoveryFromAlmExample extracts the NodeFeatureDiscovery from the alm-examples block.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ocm/placementrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func PullPlacementRule(apiClient *clients.Settings, name, nsname string) (*Place
return nil, err
}

builder := PlacementRuleBuilder{
builder := &PlacementRuleBuilder{
apiClient: apiClient.Client,
Definition: &placementrulev1.PlacementRule{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -119,7 +119,7 @@ func PullPlacementRule(apiClient *clients.Settings, name, nsname string) (*Place

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Exists checks whether the given placementrule exists.
Expand Down
4 changes: 2 additions & 2 deletions pkg/olm/clusterserviceversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func PullClusterServiceVersion(apiClient *clients.Settings, name, namespace stri
return nil, err
}

builder := ClusterServiceVersionBuilder{
builder := &ClusterServiceVersionBuilder{
apiClient: apiClient,
Definition: &oplmV1alpha1.ClusterServiceVersion{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -73,7 +73,7 @@ func PullClusterServiceVersion(apiClient *clients.Settings, name, namespace stri

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get returns ClusterServiceVersion object if found.
Expand Down
4 changes: 4 additions & 0 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,10 @@ func (builder *Builder) WithSecurityContext(securityContext *corev1.PodSecurityC

builder.isMutationAllowed("SecurityContext")

if builder.errorMsg != "" {
return builder
}

builder.Definition.Spec.SecurityContext = securityContext

return builder
Expand Down
2 changes: 1 addition & 1 deletion pkg/rbac/clusterrole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestNewClusterRoleBuilder(t *testing.T) {
rule: rbacv1.PolicyRule{
Resources: []string{"pods"}, APIGroups: []string{"v1"}, Verbs: []string{"get"}},
client: false,
expectedErrorText: "clusterRole builder cannot have nil apiClient",
expectedErrorText: "",
},
{
name: "",
Expand Down
Loading

0 comments on commit 0d5077b

Please sign in to comment.