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 May 22, 2024
1 parent f38e4f9 commit bc66ab6
Show file tree
Hide file tree
Showing 92 changed files with 1,094 additions and 872 deletions.
20 changes: 11 additions & 9 deletions pkg/argocd/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func PullApplication(apiClient *clients.Settings, name, nsname string) (*Applica
return nil, fmt.Errorf("application 'apiClient' cannot be empty")
}

builder := ApplicationBuilder{
builder := &ApplicationBuilder{
apiClient: apiClient,
Definition: &argocdtypes.Application{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -72,7 +72,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 @@ -237,18 +237,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 @@ -257,10 +263,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 @@ -289,13 +291,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 All @@ -320,5 +322,5 @@ func (builder *ApplicationBuilder) convertToStructured(
return nil, err
}

return application, err
return application, nil
}
12 changes: 8 additions & 4 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Builder struct {

// NewBuilder creates a new instance of Builder.
func NewBuilder(apiClient *clients.Settings, name, nsname string) *Builder {
builder := Builder{
builder := &Builder{
apiClient: apiClient.Client,
Definition: &argocdoperatorv1alpha1.ArgoCD{
Spec: argocdoperatorv1alpha1.ArgoCDSpec{},
Expand All @@ -43,15 +43,19 @@ func NewBuilder(apiClient *clients.Settings, name, nsname string) *Builder {
glog.V(100).Infof("The name of the argocd is empty")

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

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 @@ -228,13 +232,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 @@ -372,13 +364,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 @@ -54,7 +54,7 @@ func NewAgentClusterInstallBuilder(
return nil
}

builder := AgentClusterInstallBuilder{
builder := &AgentClusterInstallBuilder{
apiClient: apiClient.Client,
Definition: &hiveextV1Beta1.AgentClusterInstall{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -78,21 +78,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 @@ -105,9 +111,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 @@ -126,9 +130,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 @@ -147,9 +149,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 @@ -168,9 +168,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 @@ -277,15 +275,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 @@ -306,9 +304,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 @@ -594,7 +590,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 @@ -728,13 +723,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 bc66ab6

Please sign in to comment.