Skip to content

Commit

Permalink
Merge pull request #1745 from jichenjc/bug/1742
Browse files Browse the repository at this point in the history
✨remove flavor check to relief restrictions to CPU
  • Loading branch information
k8s-ci-robot authored Nov 15, 2023
2 parents 2858626 + 3f5343b commit 24c0f0c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func reconcileBastion(scope scope.Scope, cluster *clusterv1.Cluster, openStackCl
}
}

instanceStatus, err = computeService.CreateInstance(openStackCluster, openStackCluster, instanceSpec, cluster.Name, true)
instanceStatus, err = computeService.CreateInstance(openStackCluster, openStackCluster, instanceSpec, cluster.Name)
if err != nil {
return fmt.Errorf("failed to reconcile bastion: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (r *OpenStackMachineReconciler) getOrCreate(logger logr.Logger, cluster *cl
if instanceStatus == nil {
instanceSpec := machineToInstanceSpec(openStackCluster, machine, openStackMachine, userData)
logger.Info("Machine does not exist, creating Machine", "name", openStackMachine.Name)
instanceStatus, err = computeService.CreateInstance(openStackMachine, openStackCluster, instanceSpec, cluster.Name, false)
instanceStatus, err = computeService.CreateInstance(openStackMachine, openStackCluster, instanceSpec, cluster.Name)
if err != nil {
conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceCreateFailedReason, clusterv1.ConditionSeverityError, err.Error())
return nil, fmt.Errorf("create OpenStack instance: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions docs/book/src/clusteropenstack/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ The DNS servers must be exposed as an environment variable `OPENSTACK_DNS_NAMESE

The flavors for control plane and worker node machines must be exposed as environment variables `OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR` and `OPENSTACK_NODE_MACHINE_FLAVOR` respectively.

The recommmend minimum value of control plane flavor's vCPU is 2 and minimum value of worker node flavor's vCPU is 1.

# Optional Configuration

## Log level
Expand Down
13 changes: 5 additions & 8 deletions pkg/cloud/services/compute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,20 @@ func (s *Service) constructPorts(openStackCluster *infrav1.OpenStackCluster, ins
return ports, nil
}

func (s *Service) CreateInstance(eventObject runtime.Object, openStackCluster *infrav1.OpenStackCluster, instanceSpec *InstanceSpec, clusterName string, isBastion bool) (*InstanceStatus, error) {
return s.createInstanceImpl(eventObject, openStackCluster, instanceSpec, clusterName, isBastion, retryIntervalInstanceStatus)
func (s *Service) CreateInstance(eventObject runtime.Object, openStackCluster *infrav1.OpenStackCluster, instanceSpec *InstanceSpec, clusterName string) (*InstanceStatus, error) {
return s.createInstanceImpl(eventObject, openStackCluster, instanceSpec, clusterName, retryIntervalInstanceStatus)
}

func (s *Service) getAndValidateFlavor(flavorName string, isBastion bool) (*flavors.Flavor, error) {
func (s *Service) getAndValidateFlavor(flavorName string) (*flavors.Flavor, error) {
f, err := s.getComputeClient().GetFlavorFromName(flavorName)
if err != nil {
return nil, fmt.Errorf("error getting flavor from flavor name %s: %v", flavorName, err)
}
if !isBastion && f.VCPUs <= 1 {
return nil, fmt.Errorf("kubeadm requires a minimum of 2 vCPUs, pick a flavor with at least 2 vCPUs")
}

return f, nil
}

func (s *Service) createInstanceImpl(eventObject runtime.Object, openStackCluster *infrav1.OpenStackCluster, instanceSpec *InstanceSpec, clusterName string, isBastion bool, retryInterval time.Duration) (*InstanceStatus, error) {
func (s *Service) createInstanceImpl(eventObject runtime.Object, openStackCluster *infrav1.OpenStackCluster, instanceSpec *InstanceSpec, clusterName string, retryInterval time.Duration) (*InstanceStatus, error) {
var server *clients.ServerExt
portList := []servers.Network{}

Expand All @@ -246,7 +243,7 @@ func (s *Service) createInstanceImpl(eventObject runtime.Object, openStackCluste
return nil, fmt.Errorf("error getting image ID: %v", err)
}

flavor, err := s.getAndValidateFlavor(instanceSpec.Flavor, isBastion)
flavor, err := s.getAndValidateFlavor(instanceSpec.Flavor)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/services/compute/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ func TestService_ReconcileInstance(t *testing.T) {
}

// Call CreateInstance with a reduced retry interval to speed up the test
_, err = s.createInstanceImpl(&infrav1.OpenStackMachine{}, getDefaultOpenStackCluster(), tt.getInstanceSpec(), "cluster-name", false, time.Nanosecond)
_, err = s.createInstanceImpl(&infrav1.OpenStackMachine{}, getDefaultOpenStackCluster(), tt.getInstanceSpec(), "cluster-name", time.Nanosecond)
if (err != nil) != tt.wantErr {
t.Errorf("Service.CreateInstance() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit 24c0f0c

Please sign in to comment.