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

Implementation of Conditions feature in Openstack Machine Controller #972

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aa281b7
[WIP] Implemntation of Conditions feature in CAPO
swapnilbabladkar Aug 18, 2021
3046a99
[WIP] Implemntation of Conditions feature in CAPO
swapnilbabladkar Aug 18, 2021
8da6773
[WIP] Implemntation of Conditions feature in CAPO
swapnilbabladkar Aug 18, 2021
feb5851
[WIP] Implemntation of Conditions feature in CAPO
swapnilbabladkar Aug 18, 2021
f31eb82
Merge branch 'master' into test
swapnilbabladkar Sep 13, 2021
f702ab3
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
46c8181
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
82db36a
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
aaa4f23
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
87ce61f
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
8f204c6
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
6e06720
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
2dc690d
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
b593149
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
6de4bae
[WIP] - Fixes to machine controller for adding conditions
swapnilbabladkar Sep 13, 2021
35eded1
Merge branch 'master' into test
swapnilbabladkar Oct 6, 2021
7ca2a31
Removing unused varailbes from constants
swapnilbabladkar Oct 6, 2021
51cbf77
Support for conditions in machine not running state, name change for …
swapnilbabladkar Oct 6, 2021
bac8fe7
Fixing syntax for machinecontroller
swapnilbabladkar Oct 6, 2021
ac3a67e
Changes as follows in this commit :
swapnilbabladkar Oct 8, 2021
1548ca1
Fixes for gofmt with conditions file
swapnilbabladkar Oct 8, 2021
27f6a56
Fixes as follows :
swapnilbabladkar Nov 15, 2021
d1a845f
Merge branch 'main' into test
swapnilbabladkar Nov 26, 2021
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
35 changes: 35 additions & 0 deletions api/v1alpha4/condition_consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that v1beta1 is created, add api/v1beta1/condition_consts.go instead of this,please.

Copyright 2021 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 v1alpha4

import clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"

// OpenStackInstance Conditions and Reasons.
const (
// InstanceRunningCondition reports on current status of the Openstack Instance.
InstanceRunningCondition clusterv1.ConditionType = "InstanceRunning"
// InstanceCreatingReason used when the Instance creation is in progress.
InstanceCreatingReason = "InstanceCreating"
// InstanceNotFoundReason used when the Instance couldn't be retrieved.
InstanceNotFoundReason = "InstanceNotFound"
// InstanceProvisionFailedReason used for failures during Instance provisioning.
InstanceProvisionFailedReason = "InstanceProvisionFailed"
// WaitingForClusterInfrastructureReason used when Instance is waiting for cluster infrastructure to be ready before proceeding.
WaitingForClusterInfrastructureReason = "WaitingForClusterInfrastructure"
// WaitingForBootstrapDataReason used when Instance is waiting for bootstrap data to be ready before proceeding.
WaitingForBootstrapDataReason = "WaitingForBootstrapData"
)
15 changes: 15 additions & 0 deletions api/v1alpha4/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha4
import (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that v1beta1 is created, update api/v1beta1/openstackmachine_types.go instead of this, please.

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
"sigs.k8s.io/cluster-api/errors"
)

Expand Down Expand Up @@ -127,6 +128,20 @@ type OpenStackMachineStatus struct {
// controller's output.
// +optional
FailureMessage *string `json:"errorMessage,omitempty"`

// Conditions defines current service state of the OpenStackMachine.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

// GetConditions returns the observations of the operational state of the OpenStackMachine resource.
func (r *OpenStackMachine) GetConditions() clusterv1.Conditions {
return r.Status.Conditions
}

// SetConditions sets the underlying service state of the OpenStackMachine to the predescribed clusterv1.Conditions.
func (r *OpenStackMachine) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}

// +kubebuilder:object:root=true
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha4/zz_generated.deepcopy.go

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
Expand Up @@ -323,6 +323,51 @@ spec:
- type
type: object
type: array
conditions:
description: Conditions provide observations of the operational state
of a Cluster API resource.
items:
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition. This field may be empty.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase. The specific API may choose whether or not this
field is considered a guaranteed API. This field may not be
empty.
type: string
severity:
description: Severity provides an explicit classification of
Reason code, so the users or machines can immediately understand
the current situation and act accordingly. The Severity field
MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important.
type: string
required:
- status
- type
type: object
type: array
errorMessage:
description: "FailureMessage will be set in the event that there is
a terminal problem reconciling the Machine and will contain a more
Expand Down Expand Up @@ -1155,6 +1200,50 @@ spec:
- type
type: object
type: array
conditions:
description: Conditions defines current service state of the OpenStackMachine.
items:
description: Condition defines an observation of a Cluster API resource
operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition. This field may be empty.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase. The specific API may choose whether or not this
field is considered a guaranteed API. This field may not be
empty.
type: string
severity:
description: Severity provides an explicit classification of
Reason code, so the users or machines can immediately understand
the current situation and act accordingly. The Severity field
MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important.
type: string
required:
- status
- type
type: object
type: array
errorMessage:
description: "FailureMessage will be set in the event that there is
a terminal problem reconciling the Machine and will contain a more
Expand Down
7 changes: 7 additions & 0 deletions controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
capierrors "sigs.k8s.io/cluster-api/errors"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -230,6 +231,7 @@ func (r *OpenStackMachineReconciler) reconcileDelete(ctx context.Context, logger
instanceNS, err := instanceStatus.NetworkStatus()
if err != nil {
handleUpdateMachineError(logger, openStackMachine, errors.Errorf("error getting network status for OpenStack instance %s with ID %s: %v", instanceStatus.Name(), instanceStatus.ID(), err))
conditions.MarkFalse(openStackMachine, infrav1.InstanceRunningCondition, clusterv1.DeletionFailedReason, clusterv1.ConditionSeverityWarning, err.Error())
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -274,12 +276,14 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, logger

if !cluster.Status.InfrastructureReady {
logger.Info("Cluster infrastructure is not ready yet, requeuing machine")
conditions.MarkFalse(openStackMachine, infrav1.InstanceRunningCondition, infrav1.WaitingForClusterInfrastructureReason, clusterv1.ConditionSeverityInfo, "")
return ctrl.Result{RequeueAfter: waitForClusterInfrastructureReadyDuration}, nil
}

// Make sure bootstrap data is available and populated.
if machine.Spec.Bootstrap.DataSecretName == nil {
logger.Info("Bootstrap data secret reference is not yet available")
conditions.MarkFalse(openStackMachine, infrav1.InstanceRunningCondition, infrav1.WaitingForBootstrapDataReason, clusterv1.ConditionSeverityInfo, "")
return ctrl.Result{}, nil
}
userData, err := r.getBootstrapData(ctx, machine, openStackMachine)
Expand Down Expand Up @@ -308,12 +312,14 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, logger
instanceStatus, err := r.getOrCreate(logger, cluster, openStackCluster, machine, openStackMachine, computeService, userData)
if err != nil {
handleUpdateMachineError(logger, openStackMachine, errors.Errorf("OpenStack instance cannot be created: %v", err))
conditions.MarkFalse(openStackMachine, infrav1.InstanceRunningCondition, infrav1.InstanceProvisionFailedReason, clusterv1.ConditionSeverityError, err.Error())
return ctrl.Result{}, err
}

// Set an error message if we couldn't find the instance.
if instanceStatus == nil {
handleUpdateMachineError(logger, openStackMachine, errors.New("OpenStack instance cannot be found"))
conditions.MarkUnknown(openStackMachine, infrav1.InstanceRunningCondition, infrav1.InstanceNotFoundReason, err.Error())
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -341,6 +347,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, logger
case infrav1.InstanceStateError:
// Error is unexpected, thus we report error and never retry
handleUpdateMachineError(logger, openStackMachine, errors.Errorf("OpenStack instance state %q is unexpected", instanceStatus.State()))
conditions.MarkUnknown(openStackMachine, infrav1.InstanceRunningCondition, "", "")
return ctrl.Result{}, nil
case infrav1.InstanceStateDeleted:
// we should avoid further actions for DELETED VM
Expand Down