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 Dec 16, 2024
1 parent 0f9dd43 commit 8dfc26e
Show file tree
Hide file tree
Showing 91 changed files with 854 additions and 737 deletions.
18 changes: 10 additions & 8 deletions pkg/argocd/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func PullApplication(apiClient *clients.Settings, name, nsname string) (*Applica
return nil, err
}

builder := ApplicationBuilder{
builder := &ApplicationBuilder{
apiClient: apiClient.Client,
Definition: &argocdtypes.Application{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -73,7 +73,7 @@ func PullApplication(apiClient *clients.Settings, name, nsname string) (*Applica

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Exists checks whether the given argocd application exists.
Expand Down Expand Up @@ -219,18 +219,24 @@ func (builder *ApplicationBuilder) WithGitDetails(gitRepo, gitBranch, gitPath st
glog.V(100).Infof("The 'gitRepo' of the argocd application is empty")

builder.errorMsg = "'gitRepo' parameter is empty"

return builder
}

if gitBranch == "" {
glog.V(100).Infof("The 'gitBranch' of the argocd application is empty")

builder.errorMsg = "'gitBranch' parameter is empty"

return builder
}

if gitPath == "" {
glog.V(100).Infof("The 'gitPath' of the argocd application is empty")

builder.errorMsg = "'gitPath' parameter is empty"

return builder
}

glog.V(100).Infof(
Expand All @@ -239,10 +245,6 @@ func (builder *ApplicationBuilder) WithGitDetails(gitRepo, gitBranch, gitPath st
gitRepo, gitBranch, gitPath,
)

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

builder.Definition.Spec.Source.RepoURL = gitRepo
builder.Definition.Spec.Source.TargetRevision = gitBranch
builder.Definition.Spec.Source.Path = gitPath
Expand Down Expand Up @@ -316,13 +318,13 @@ func (builder *ApplicationBuilder) 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
12 changes: 7 additions & 5 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewBuilder(apiClient *clients.Settings, name, nsname string) *Builder {
return nil
}

builder := Builder{
builder := &Builder{
apiClient: apiClient.Client,
Definition: &argocdoperator.ArgoCD{
Spec: argocdoperator.ArgoCDSpec{},
Expand All @@ -59,16 +59,18 @@ func NewBuilder(apiClient *clients.Settings, name, nsname string) *Builder {

builder.errorMsg = "argocd 'name' cannot be empty"

return &builder
return builder
}

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

builder.errorMsg = "argocd 'nsname' cannot be empty"

return builder
}

return &builder
return builder
}

// Pull pulls existing argocd from cluster.
Expand Down Expand Up @@ -252,13 +254,13 @@ func (builder *Builder) 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
20 changes: 6 additions & 14 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 @@ -74,13 +74,13 @@ func PullAgent(apiClient *clients.Settings, name, nsname string) (*agentBuilder,
if name == "" {
glog.V(100).Infof("The name of the agent is empty")

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

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

builder.errorMsg = "agent 'namespace' cannot be empty"
return nil, fmt.Errorf("agent 'namespace' cannot be empty")
}

if !builder.Exists() {
Expand All @@ -106,9 +106,7 @@ func (builder *agentBuilder) WithHostName(hostname string) *agentBuilder {
builder.Definition.Name, builder.Definition.Namespace)

builder.errorMsg = nonExistentMsg
}

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

Expand All @@ -131,9 +129,7 @@ func (builder *agentBuilder) WithRole(role string) *agentBuilder {
builder.Definition.Name, builder.Definition.Namespace)

builder.errorMsg = nonExistentMsg
}

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

Expand Down Expand Up @@ -304,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 Expand Up @@ -377,13 +369,13 @@ func (builder *agentBuilder) 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
29 changes: 12 additions & 17 deletions pkg/assisted/agentclusterinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewAgentClusterInstallBuilder(
return nil
}

builder := AgentClusterInstallBuilder{
builder := &AgentClusterInstallBuilder{
apiClient: apiClient.Client,
Definition: &hiveextV1Beta1.AgentClusterInstall{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -85,21 +85,27 @@ func NewAgentClusterInstallBuilder(
glog.V(100).Infof("The name of the agentclusterinstall is empty")

builder.errorMsg = "agentclusterinstall 'name' cannot be empty"

return builder
}

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

builder.errorMsg = "agentclusterinstall 'namespace' cannot be empty"

return builder
}

if clusterDeployment == "" {
glog.V(100).Infof("The clusterDeployment ref for the agentclusterinstall is empty")

builder.errorMsg = "agentclusterinstall 'clusterDeployment' cannot be empty"

return builder
}

return &builder
return builder
}

// WithAPIVip sets the apiVIP to use during multi-node installations.
Expand All @@ -112,9 +118,7 @@ func (builder *AgentClusterInstallBuilder) WithAPIVip(apiVIP string) *AgentClust
glog.V(100).Infof("The apiVIP is not a properly formatted IP address")

builder.errorMsg = "agentclusterinstall apiVIP incorrectly formatted"
}

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

Expand All @@ -133,9 +137,7 @@ func (builder *AgentClusterInstallBuilder) WithAdditionalAPIVip(apiVIP string) *
glog.V(100).Infof("The apiVIP is not a properly formatted IP address")

builder.errorMsg = "agentclusterinstall apiVIP incorrectly formatted"
}

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

Expand All @@ -154,9 +156,7 @@ func (builder *AgentClusterInstallBuilder) WithIngressVip(ingressVIP string) *Ag
glog.V(100).Infof("The ingressVIP is not a properly formatted IP address")

builder.errorMsg = "agentclusterinstall ingressVIP incorrectly formatted"
}

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

Expand All @@ -175,9 +175,7 @@ func (builder *AgentClusterInstallBuilder) WithAdditionalIngressVip(ingressVIP s
glog.V(100).Infof("The ingressVIP is not a properly formatted IP address")

builder.errorMsg = "agentclusterinstall ingressVIP incorrectly formatted"
}

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

Expand Down Expand Up @@ -284,15 +282,15 @@ func (builder *AgentClusterInstallBuilder) WithAdditionalClusterNetwork(
glog.V(100).Infof("The agentclusterinstall passed invalid clusterNetwork cidr: %s", cidr)

builder.errorMsg = "agentclusterinstall contains invalid clusterNetwork cidr"

return builder
}

if prefix <= 0 {
glog.V(100).Infof("Agentclusterinstall passed invalid clusterNetwork prefix: %s", cidr)

builder.errorMsg = "agentclusterinstall contains invalid clusterNetwork prefix"
}

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

Expand All @@ -313,9 +311,7 @@ func (builder *AgentClusterInstallBuilder) WithAdditionalServiceNetwork(cidr str
glog.V(100).Infof("The agentclusterinstall passed invalid serviceNetwork cidr: %s", cidr)

builder.errorMsg = "agentclusterinstall contains invalid serviceNetwork cidr"
}

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

Expand Down Expand Up @@ -608,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 Expand Up @@ -748,13 +743,13 @@ func (builder *AgentClusterInstallBuilder) 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
Loading

0 comments on commit 8dfc26e

Please sign in to comment.