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 2, 2025
1 parent 6085a8f commit 136a5a9
Show file tree
Hide file tree
Showing 71 changed files with 496 additions and 431 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
2 changes: 2 additions & 0 deletions pkg/kmm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ func (builder *ModuleBuilder) withServiceAccount(srvAccountName string, accountT
builder.Definition.Spec.DevicePlugin.ServiceAccountName = srvAccountName
default:
builder.errorMsg = "invalid account type parameter. Supported parameters are: 'module', 'device'"

return builder
}

return builder
Expand Down
6 changes: 1 addition & 5 deletions pkg/lca/imagebasedupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ func (builder *ImageBasedUpgradeBuilder) Update() (*ImageBasedUpgradeBuilder, er
glog.V(100).Infof("imagebasedupgrade %s does not exist",
builder.Definition.Name)

builder.errorMsg = "Unable to update non-existing imagebasedupgrade"
}

if builder.errorMsg != "" {
return nil, fmt.Errorf(builder.errorMsg)
return nil, fmt.Errorf("unable to update non-existing imagebasedupgrade")
}

err := builder.apiClient.Update(context.TODO(), builder.Definition)
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
7 changes: 2 additions & 5 deletions pkg/metallb/addresspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ func (builder *IPAddressPoolBuilder) Create() (*IPAddressPoolBuilder, error) {
builder.Definition.Name, builder.Definition.Namespace,
)

var err error
if !builder.Exists() {
err = builder.apiClient.Create(context.TODO(), builder.Definition)
err := builder.apiClient.Create(context.TODO(), builder.Definition)
if err != nil {
glog.V(100).Infof("Failed to create IPAddressPool")

Expand All @@ -192,7 +191,7 @@ func (builder *IPAddressPoolBuilder) Create() (*IPAddressPoolBuilder, error) {

builder.Object = builder.Definition

return builder, err
return builder, nil
}

// Delete removes IPAddressPool object from a cluster.
Expand Down Expand Up @@ -304,9 +303,7 @@ func (builder *IPAddressPoolBuilder) WithOptions(options ...IPAddressPoolAdditio
glog.V(100).Infof("The IPAddressPool is undefined")

builder.errorMsg = msg.UndefinedCrdObjectErrString("IPAddressPool")
}

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

Expand Down
4 changes: 4 additions & 0 deletions pkg/metallb/bfdprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ func (builder *BFDBuilder) withBoolFlagFor(flagName string, flagValue bool) *BFD
builder.Definition.Spec.PassiveMode = &flagValue
default:
builder.errorMsg = "invalid bool flag name parameter"

return builder
}

return builder
Expand All @@ -377,6 +379,8 @@ func (builder *BFDBuilder) withInterval(intervalName string, interval uint32) *B
builder.Definition.Spec.EchoInterval = &interval
default:
builder.errorMsg = "invalid interval parameters"

return builder
}

return builder
Expand Down
7 changes: 3 additions & 4 deletions pkg/metallb/bgpadvertisement.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ func (builder *BGPAdvertisementBuilder) Create() (*BGPAdvertisementBuilder, erro
builder.Definition.Name, builder.Definition.Namespace,
)

var err error
if !builder.Exists() {
err = builder.apiClient.Create(context.TODO(), builder.Definition)
err := builder.apiClient.Create(context.TODO(), builder.Definition)

if err != nil {
glog.V(100).Infof("Failed to create BGPAdvertisement")
Expand All @@ -181,7 +180,7 @@ func (builder *BGPAdvertisementBuilder) Create() (*BGPAdvertisementBuilder, erro

builder.Object = builder.Definition

return builder, err
return builder, nil
}

// Delete removes BGPAdvertisement object from a cluster.
Expand Down Expand Up @@ -255,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
9 changes: 4 additions & 5 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 All @@ -184,16 +184,15 @@ func (builder *BGPPeerBuilder) Create() (*BGPPeerBuilder, error) {
builder.Definition.Name, builder.Definition.Namespace,
)

var err error
if !builder.Exists() {
err = builder.apiClient.Create(context.TODO(), builder.Definition)
err := builder.apiClient.Create(context.TODO(), builder.Definition)

if err == nil {
builder.Object = builder.Definition
}
}

return builder, err
return builder, nil
}

// Delete removes BGPPeer object from a cluster.
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
5 changes: 2 additions & 3 deletions pkg/metallb/metallb.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,15 @@ func (builder *Builder) Create() (*Builder, error) {
builder.Definition.Name, builder.Definition.Namespace,
)

var err error
if !builder.Exists() {
err = builder.apiClient.Create(context.TODO(), builder.Definition)
err := builder.apiClient.Create(context.TODO(), builder.Definition)

if err == nil {
builder.Object = builder.Definition
}
}

return builder, err
return builder, nil
}

// Delete removes MetalLb object from a cluster.
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
Loading

0 comments on commit 136a5a9

Please sign in to comment.