Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

servicemesh: adjust return consistency #865

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions pkg/servicemesh/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ func NewControlPlaneBuilder(apiClient *clients.Settings, name, nsname string) *C
glog.V(100).Infof("The name of the serviceMeshControlPlane is empty")

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

return builder
}

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

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

return builder
}

return builder
Expand Down Expand Up @@ -121,17 +125,17 @@ func (builder *ControlPlaneBuilder) WithGrafanaAddon(
glog.V(100).Infof("The grafanaInstallConfig of the Grafana addon is empty")

builder.errorMsg = "the Grafana addon 'grafanaInstallConfig' cannot be empty when Grafana addon is enabled"

return builder
}

if address == "" {
glog.V(100).Infof("The address of the Grafana addon is empty")

builder.errorMsg = "the Grafana addon 'address' cannot be empty when Grafana addon is enabled"
}
}

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

addonConfig := &istiov2.GrafanaAddonConfig{
Expand Down Expand Up @@ -167,15 +171,15 @@ func (builder *ControlPlaneBuilder) WithJaegerAddon(
glog.V(100).Infof("The name of the Jaeger addon is empty")

builder.errorMsg = "the Jaeger addon 'name' cannot be empty"

return builder
}

if jaegerInstallConfig == nil {
glog.V(100).Infof("The jaegerInstallConfig of the Jaeger addon is empty")

builder.errorMsg = "the Jaeger addon 'jaegerInstallConfig' cannot be empty"
}

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

Expand Down Expand Up @@ -211,17 +215,17 @@ func (builder *ControlPlaneBuilder) WithKialiAddon(
glog.V(100).Infof("The kialiInstallConfig of the Kiali addon is empty")

builder.errorMsg = "the Kiali addon 'kialiInstallConfig' cannot be empty when Kiali addon is enabled"

return builder
}

if name == "" {
glog.V(100).Infof("The name of the Kiali addon is empty")

builder.errorMsg = "the Kiali addon 'name' cannot be empty when Kiali addon is enabled"
}
}

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

addonConfig := &istiov2.KialiAddonConfig{
Expand Down Expand Up @@ -262,24 +266,26 @@ func (builder *ControlPlaneBuilder) WithPrometheusAddon(

builder.errorMsg = "the Prometheus addon 'prometheusInstallConfig' cannot " +
"be empty when Prometheus addon is enabled"

return builder
}

if metricsExpiryDuration == "" {
glog.V(100).Info("The metricsExpiryDuration of the Prometheus addon is empty")

builder.errorMsg = "the Prometheus addon 'metricsExpiryDuration' cannot " +
"be empty when Prometheus addon is enabled"

return builder
}

if address == "" {
glog.V(100).Info("The address of the Prometheus addon is empty")

builder.errorMsg = "the Prometheus addon 'address' cannot be empty when Prometheus addon is enabled"
}
}

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

addonConfig := &istiov2.PrometheusAddonConfig{
Expand Down Expand Up @@ -340,7 +346,7 @@ func PullControlPlane(apiClient *clients.Settings, name, nsname string) (*Contro
return nil, err
}

builder := ControlPlaneBuilder{
builder := &ControlPlaneBuilder{
apiClient: apiClient.Client,
Definition: &istiov2.ServiceMeshControlPlane{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -362,17 +368,13 @@ func PullControlPlane(apiClient *clients.Settings, name, nsname string) (*Contro
return nil, fmt.Errorf("serviceMeshControlPlane 'nsname' cannot be empty")
}

if builder.errorMsg != "" {
return &builder, nil
}

if !builder.Exists() {
return nil, fmt.Errorf("serviceMeshControlPlane object %s does not exist in namespace %s", name, nsname)
}

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get fetches existing serviceMeshControlPlane from cluster.
Expand Down Expand Up @@ -514,13 +516,13 @@ func (builder *ControlPlaneBuilder) 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
14 changes: 8 additions & 6 deletions pkg/servicemesh/memberroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ func NewMemberRollBuilder(apiClient *clients.Settings, name, nsname string) *Mem
glog.V(100).Infof("The name of the serviceMeshMemberRoll is empty")

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

return builder
}

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

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

return builder
}

return builder
Expand All @@ -92,7 +96,7 @@ func PullMemberRoll(apiClient *clients.Settings, name, nsname string) (*MemberRo
return nil, err
}

builder := MemberRollBuilder{
builder := &MemberRollBuilder{
apiClient: apiClient.Client,
Definition: &istiov1.ServiceMeshMemberRoll{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -120,7 +124,7 @@ func PullMemberRoll(apiClient *clients.Settings, name, nsname string) (*MemberRo

builder.Definition = builder.Object

return &builder, nil
return builder, nil
}

// Get fetches existing serviceMeshMemberRoll from cluster.
Expand Down Expand Up @@ -254,9 +258,7 @@ func (builder *MemberRollBuilder) WithMembersList(membersList []string) *MemberR
glog.V(100).Infof("Cannot add empty membersList to the memberRoll structure")

builder.errorMsg = "can not modify memberRoll config with empty membersList"
}

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

Expand Down Expand Up @@ -331,13 +333,13 @@ func (builder *MemberRollBuilder) 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