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

Add unit tests for agentserviceconfig #437

Merged
merged 1 commit into from
May 28, 2024
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
42 changes: 25 additions & 17 deletions pkg/assisted/agentserviceconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/utils/strings/slices"
goclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -24,6 +25,10 @@ const (
defaultImageStoreStorageSize = "10Gi"
)

var (
validIPXEOptions = []string{"enabled", "disabled"}
)

// AgentServiceConfigBuilder provides struct for the agentserviceconfig object containing connection to
// the cluster and the agentserviceconfig definition.
type AgentServiceConfigBuilder struct {
Expand Down Expand Up @@ -180,6 +185,14 @@ func (builder *AgentServiceConfigBuilder) WithUnauthenticatedRegistry(registry s

glog.V(100).Infof("Adding unauthenticatedRegistry %s to agentserviceconfig %s", registry, builder.Definition.Name)

if registry == "" {
glog.V(100).Infof("AgentServiceConfig UnauthenticatedRegistry supplied empty registry")

builder.errorMsg = "agentserviceconfig cannot have empty unauthenticated registry"

return builder
}

builder.Definition.Spec.UnauthenticatedRegistries = append(builder.Definition.Spec.UnauthenticatedRegistries, registry)

return builder
Expand All @@ -193,6 +206,15 @@ func (builder *AgentServiceConfigBuilder) WithIPXEHTTPRoute(route string) *Agent

glog.V(100).Infof("Adding IPXEHTTPRout %s to agentserviceconfig %s", route, builder.Definition.Name)

if !slices.Contains(validIPXEOptions, route) {
glog.V(100).Infof("Receieved incorrect IPXEHTTPRoute option: %s, valid options: %v", route, validIPXEOptions)

builder.errorMsg =
fmt.Sprintf("agentserviceconfig passed invalid ipxeroute: %s, valid options: %v", route, validIPXEOptions)

return builder
}

builder.Definition.Spec.IPXEHTTPRoute = route

return builder
Expand Down Expand Up @@ -232,20 +254,10 @@ func (builder *AgentServiceConfigBuilder) WaitUntilDeployed(timeout time.Duratio

glog.V(100).Infof("Waiting for agetserviceconfig %s to be deployed", builder.Definition.Name)

if builder.Definition == nil {
glog.V(100).Infof("The agentserviceconfig is undefined")

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

if !builder.Exists() {
glog.V(100).Infof("The agentserviceconfig does not exist on the cluster")

builder.errorMsg = "cannot wait for non-existent agentserviceconfig to be deployed"
}

if builder.errorMsg != "" {
return builder, fmt.Errorf(builder.errorMsg)
return builder, 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 @@ -365,11 +377,7 @@ func (builder *AgentServiceConfigBuilder) Update(force bool) (*AgentServiceConfi
glog.V(100).Infof("agentserviceconfig %s does not exist",
builder.Definition.Name)

builder.errorMsg = "Cannot update non-existent agentserviceconfig"
}

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

err := builder.apiClient.Update(context.TODO(), builder.Definition)
Expand Down Expand Up @@ -411,7 +419,7 @@ func (builder *AgentServiceConfigBuilder) Delete() error {
builder.Definition.Name)

if !builder.Exists() {
return fmt.Errorf("agentserviceconfig cannot be deleted because it does not exist")
return nil
}

err := builder.apiClient.Delete(context.TODO(), builder.Definition)
Expand Down
Loading
Loading