-
Notifications
You must be signed in to change notification settings - Fork 36
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
Discard and replace new VMs if they never join the cluster #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1" | ||
"time" | ||
) | ||
|
||
var _ = Describe("CloudStackMachine types", func() { | ||
var cloudStackMachine infrav1.CloudStackMachine | ||
|
||
BeforeEach(func() { // Reset test vars to initial state. | ||
cloudStackMachine = infrav1.CloudStackMachine{} | ||
}) | ||
|
||
Context("When calculating time since state change", func() { | ||
It("Return the correct value when the last state update time is known", func() { | ||
delta := time.Duration(10 * time.Minute) | ||
lastUpdated := time.Now().Add(-delta) | ||
cloudStackMachine.Status.InstanceStateLastUpdated = metav1.NewTime(lastUpdated) | ||
Ω(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(BeNumerically("~", delta, time.Second)) | ||
}) | ||
|
||
It("Return a negative value when the last state update time is unknown", func() { | ||
Ω(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(BeNumerically("<", 0)) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,16 +70,33 @@ func (r *CloudStackMachineStateCheckerReconciliationRunner) Reconcile() (ctrl.Re | |
if res, err := r.GetParent(r.ReconciliationSubject, r.CSMachine)(); r.ShouldReturn(res, err) { | ||
return res, err | ||
} | ||
|
||
if res, err := r.GetParent(r.CSMachine, r.CAPIMachine)(); r.ShouldReturn(res, err) { | ||
return res, err | ||
} | ||
|
||
if err := r.CSClient.ResolveVMInstanceDetails(r.CSMachine); err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match found") { | ||
return r.ReturnWrappedError(err, "failed to resolve VM instance details") | ||
} | ||
if r.CSMachine.Status.InstanceState == "Running" { | ||
|
||
csRunning := r.CSMachine.Status.InstanceState == "Running" | ||
csTimeInState := r.CSMachine.Status.TimeSinceLastStateChange() | ||
capiRunning := r.CAPIMachine.Status.Phase == "Running" | ||
|
||
// capiTimeout indicates that a new VM is running, but it isn't reachable due to a network issue or a misconfiguration. | ||
// When this happens, the machine should be deleted or else the cluster won't ever recover. | ||
capiTimeout := csRunning && !capiRunning && csTimeInState > 5*time.Minute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be configurable instead of hardcoded? Maybe default to 5 minutes, unless some env var is set or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to have a good mechanism for making it configurable. I wish we could put something in the EKS-A cluster definition file, but nothing there passes through nicely. Is there a good way to set environment variables on the VMs in bulk? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's create a GitHub issue and move forward without this configuration for now, since it's not essential. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #127 |
||
|
||
if csRunning && capiRunning { | ||
r.ReconciliationSubject.Status.Ready = true | ||
} else { | ||
} else if !csRunning || capiTimeout { | ||
r.Log.Info("CloudStack instance in bad state", | ||
"name", r.CSMachine.Name, | ||
"instance-id", r.CSMachine.Spec.InstanceID, | ||
"cs-state", r.CSMachine.Status.InstanceState, | ||
"cs-time-in-state", csTimeInState.String(), | ||
"capi-phase", r.CAPIMachine.Status.Phase) | ||
|
||
if err := r.K8sClient.Delete(r.RequestCtx, r.CAPIMachine); err != nil { | ||
return r.ReturnWrappedError(err, "failed to delete CAPI machine") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we start adding some unit tests here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I just added some.