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 1, 2024
1 parent ecf4a63 commit 4b15168
Show file tree
Hide file tree
Showing 90 changed files with 1,088 additions and 883 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
37 changes: 13 additions & 24 deletions pkg/assisted/agentclusterinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewAgentClusterInstallBuilder(
return nil
}

builder := AgentClusterInstallBuilder{
builder := &AgentClusterInstallBuilder{
apiClient: apiClient.Client,
Definition: &hiveextV1Beta1.AgentClusterInstall{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -74,21 +74,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 @@ -101,9 +107,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 @@ -122,9 +126,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 @@ -143,9 +145,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 @@ -164,9 +164,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 @@ -265,9 +263,7 @@ func (builder *AgentClusterInstallBuilder) WithAdditionalClusterNetwork(
glog.V(100).Infof("The agentclusterinstall passed invalid clusterNetwork cidr: %s", cidr)

builder.errorMsg = "Got invalid cidr for clusternetwork"
}

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

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

builder.errorMsg = "Got invalid cidr for servicenetwork"
}

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

Expand Down Expand Up @@ -512,13 +506,13 @@ func PullAgentClusterInstall(apiClient *clients.Settings, name, nsname string) (
if name == "" {
glog.V(100).Infof("The name of the agentclusterinstall is empty")

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

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

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

if !builder.Exists() {
Expand Down Expand Up @@ -560,11 +554,7 @@ func (builder *AgentClusterInstallBuilder) Update(force bool) (*AgentClusterInst
builder.Definition.Name, builder.Definition.Namespace)

if !builder.Exists() {
builder.errorMsg = "Cannot update non-existent agentclusterinstall"
}

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

err := builder.apiClient.Update(context.TODO(), builder.Definition)
Expand All @@ -576,7 +566,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 @@ -710,13 +699,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 4b15168

Please sign in to comment.