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

Do not sent fault domain if failure domain is set as empty #352

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
40 changes: 22 additions & 18 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,33 @@ func (m *MachineScope) GetOrCreateMachine(ctx context.Context) (*core.Instance,
}

failureDomain := m.Machine.Spec.FailureDomain
if failureDomain == nil {
m.Logger.Info("Failure Domain is not set in the machine spec, setting it to a random value from 1 to 3")
randomFaultDomain, err := rand.Int(rand.Reader, big.NewInt(3))
var faultDomain string
var availabilityDomain string
if failureDomain != nil {
failureDomainIndex, err := strconv.Atoi(*failureDomain)
if err != nil {
m.Logger.Error(err, "Failed to generate random fault domain")
m.Logger.Error(err, "Failure Domain is not a valid integer")
return nil, errors.Wrap(err, "invalid failure domain parameter, must be a valid integer")
}
m.Logger.Info("Failure Domain being used", "failure-domain", failureDomainIndex)
if failureDomainIndex < 1 || failureDomainIndex > 3 {
err = errors.New("failure domain should be a value between 1 and 3")
m.Logger.Error(err, "Failure domain should be a value between 1 and 3")
return nil, err
}
faultDomain = m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[FaultDomain]
availabilityDomain = m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[AvailabilityDomain]
} else {
randomFailureDomain, err := rand.Int(rand.Reader, big.NewInt(3))
shyamradhakrishnan marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
m.Logger.Error(err, "Failed to generate random failure domain")
return nil, err
}
// the random number generated is between zero and two, whereas we need a number between one and three
failureDomain = common.String(strconv.Itoa(int(randomFaultDomain.Int64()) + 1))
}
failureDomainIndex, err := strconv.Atoi(*failureDomain)
if err != nil {
m.Logger.Error(err, "Failure Domain is not a valid integer")
return nil, errors.Wrap(err, "invalid failure domain parameter, must be a valid integer")
}
m.Logger.Info("Failure Domain being used", "failure-domain", failureDomainIndex)
if failureDomainIndex < 1 || failureDomainIndex > 3 {
err = errors.New("failure domain should be a value between 1 and 3")
m.Logger.Error(err, "Failure domain should be a value between 1 and 3")
return nil, err
failureDomain = common.String(strconv.Itoa(int(randomFailureDomain.Int64()) + 1))
availabilityDomain = m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[AvailabilityDomain]
}

metadata := m.OCIMachine.Spec.Metadata
if metadata == nil {
metadata = make(map[string]string)
Expand All @@ -231,8 +237,6 @@ func (m *MachineScope) GetOrCreateMachine(ctx context.Context) (*core.Instance,

definedTags := ConvertMachineDefinedTags(m.OCIMachine.Spec.DefinedTags)

availabilityDomain := m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[AvailabilityDomain]
faultDomain := m.OCIClusterAccessor.GetFailureDomains()[*failureDomain].Attributes[FaultDomain]
launchDetails := core.LaunchInstanceDetails{DisplayName: common.String(m.OCIMachine.Name),
SourceDetails: sourceDetails,
CreateVnicDetails: &core.CreateVnicDetails{
Expand Down
3 changes: 3 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ releaseSeries:
contract: v1beta1
- major: 0
minor: 14
contract: v1beta1
- major: 0
minor: 15
contract: v1beta1