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 agentclusterinstall #434

Merged
merged 1 commit into from
May 22, 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
46 changes: 32 additions & 14 deletions pkg/assisted/agentclusterinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
goclient "sigs.k8s.io/controller-runtime/pkg/client"
)

var (
eventsTransport http.RoundTripper
)

// AgentClusterInstallBuilder provides struct for the agentclusterinstall object containing connection to
// the cluster and the agentclusterinstall definitions.
type AgentClusterInstallBuilder struct {
Expand Down Expand Up @@ -204,6 +208,10 @@ func (builder *AgentClusterInstallBuilder) WithControlPlaneAgents(agentCount int
return builder
}

if agentCount <= 0 {
builder.errorMsg = "agentclusterinstall controlplane agents must be greater than 0"
}

builder.Definition.Spec.ProvisionRequirements.ControlPlaneAgents = agentCount

return builder
Expand All @@ -215,6 +223,10 @@ func (builder *AgentClusterInstallBuilder) WithWorkerAgents(agentCount int) *Age
return builder
}

if agentCount < 0 {
builder.errorMsg = "agentclusterinstall worker agents cannot be less that 0"
}

builder.Definition.Spec.ProvisionRequirements.WorkerAgents = agentCount

return builder
Expand Down Expand Up @@ -264,7 +276,13 @@ func (builder *AgentClusterInstallBuilder) WithAdditionalClusterNetwork(
if _, _, err := net.ParseCIDR(cidr); err != nil {
glog.V(100).Infof("The agentclusterinstall passed invalid clusterNetwork cidr: %s", cidr)

builder.errorMsg = "Got invalid cidr for clusternetwork"
builder.errorMsg = "agentclusterinstall contains invalid clusterNetwork cidr"
}

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

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

if builder.errorMsg != "" {
Expand All @@ -287,7 +305,7 @@ func (builder *AgentClusterInstallBuilder) WithAdditionalServiceNetwork(cidr str
if _, _, err := net.ParseCIDR(cidr); err != nil {
glog.V(100).Infof("The agentclusterinstall passed invalid serviceNetwork cidr: %s", cidr)

builder.errorMsg = "Got invalid cidr for servicenetwork"
builder.errorMsg = "agentclusterinstall contains invalid serviceNetwork cidr"
}

if builder.errorMsg != "" {
Expand Down Expand Up @@ -385,7 +403,7 @@ func (builder *AgentClusterInstallBuilder) WithOptions(
func (builder *AgentClusterInstallBuilder) WaitForConditionMessage(
conditionType, message string, timeout time.Duration) error {
return wait.PollUntilContextTimeout(
context.TODO(), retryInterval, timeout, false, func(ctx context.Context) (bool, error) {
context.TODO(), retryInterval, timeout, true, func(ctx context.Context) (bool, error) {
condition, err := builder.getCondition(conditionType)
if err != nil {
return false, err
Expand All @@ -399,7 +417,7 @@ func (builder *AgentClusterInstallBuilder) WaitForConditionMessage(
func (builder *AgentClusterInstallBuilder) WaitForConditionStatus(
conditionType string, status corev1.ConditionStatus, timeout time.Duration) error {
return wait.PollUntilContextTimeout(
context.TODO(), retryInterval, timeout, false, func(ctx context.Context) (bool, error) {
context.TODO(), retryInterval, timeout, true, func(ctx context.Context) (bool, error) {
condition, err := builder.getCondition(conditionType)
if err != nil {
return false, err
Expand Down Expand Up @@ -436,9 +454,13 @@ func (builder *AgentClusterInstallBuilder) GetEvents(skipCertVerify bool) (model
return nil, fmt.Errorf("cannot get events from non-existent agentclusterinstall")
}

client := http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipCertVerify}}}
if eventsTransport == nil {
eventsTransport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: skipCertVerify}}
}

client := http.Client{Transport: eventsTransport}

glog.V(100).Infof("Getting events from url: %s", builder.Object.Status.DebugInfo.EventsURL)

Expand Down Expand Up @@ -512,13 +534,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 +582,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 Down
Loading
Loading