-
Notifications
You must be signed in to change notification settings - Fork 17
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
Bmcjob controller implementation #6
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3331766
Updating BMCJob Condition
pokearu 4a88790
Updating BMCTask Condition
pokearu c182e65
Removing BMCTask controller and adding BMCTaskHandler struct
pokearu 565a84e
BMCJob controller implementation
pokearu 52c8b88
Refactoring SetCondition methods
pokearu 979d648
Moving errors around and aggregating
pokearu fa270bd
Adding PausedAnnotation to BaseboardManagement
pokearu ec9d0b4
Generalizing ConditionStatus and adding comments
pokearu 16fdead
Renaming BaseboardManagementRef get method
pokearu 6088fd8
Deleting taskhandler and implementing task controller
pokearu be8c036
Making LastUpdatedTime optional and updating only on condition status…
pokearu c0e503e
Updating API and adding HasCondition helper
pokearu c0d6de2
Refactoring bmcjob controller to watch BMCTasks and create new tasks …
pokearu da2a6b2
Removing struct representation for Task.PowerAction
pokearu e85f60d
Modifying job reconcile to patch finally on every run
pokearu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ limitations under the License. | |
package v1alpha1 | ||
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. A general comment: why are we using |
||
|
||
import ( | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
|
@@ -32,16 +34,16 @@ const ( | |
JobRunning BMCJobConditionType = "Running" | ||
) | ||
|
||
// PowerControl represents the power control operation on the baseboard management. | ||
type PowerControl string | ||
// PowerAction represents the power control operation on the baseboard management. | ||
type PowerAction string | ||
|
||
const ( | ||
PowerOn PowerControl = "on" | ||
HardPowerOff PowerControl = "off" | ||
SoftPowerOff PowerControl = "soft" | ||
Cycle PowerControl = "cycle" | ||
Reset PowerControl = "reset" | ||
Status PowerControl = "status" | ||
PowerOn PowerAction = "on" | ||
HardPowerOff PowerAction = "off" | ||
SoftPowerOff PowerAction = "soft" | ||
Cycle PowerAction = "cycle" | ||
Reset PowerAction = "reset" | ||
Status PowerAction = "status" | ||
) | ||
|
||
// BMCJobSpec defines the desired state of BMCJob | ||
|
@@ -77,11 +79,68 @@ type BMCJobCondition struct { | |
// Type of the BMCJob condition. | ||
Type BMCJobConditionType `json:"type"` | ||
|
||
// Status is the status of the BMCJob condition. | ||
// Can be True or False. | ||
Status ConditionStatus `json:"status"` | ||
|
||
// Message represents human readable message indicating details about last transition. | ||
// +optional | ||
Message string `json:"message,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:generate=false | ||
type BMCJobSetConditionOption func(*BMCJobCondition) | ||
|
||
// SetCondition applies the cType condition to bmj. If the condition already exists, | ||
// it is updated. | ||
func (bmj *BMCJob) SetCondition(cType BMCJobConditionType, status ConditionStatus, opts ...BMCJobSetConditionOption) { | ||
var condition *BMCJobCondition | ||
|
||
// Check if there's an existing condition. | ||
for i, c := range bmj.Status.Conditions { | ||
if c.Type == cType { | ||
condition = &bmj.Status.Conditions[i] | ||
break | ||
} | ||
} | ||
|
||
// We didn't find an existing condition so create a new one and append it. | ||
if condition == nil { | ||
bmj.Status.Conditions = append(bmj.Status.Conditions, BMCJobCondition{ | ||
Type: cType, | ||
}) | ||
condition = &bmj.Status.Conditions[len(bmj.Status.Conditions)-1] | ||
} | ||
|
||
condition.Status = status | ||
for _, opt := range opts { | ||
opt(condition) | ||
} | ||
} | ||
|
||
// WithJobConditionMessage sets message m to the BMCJobCondition. | ||
func WithJobConditionMessage(m string) BMCJobSetConditionOption { | ||
pokearu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return func(c *BMCJobCondition) { | ||
c.Message = m | ||
} | ||
} | ||
|
||
// HasCondition checks if the cType condition is present with status cStatus on a bmj. | ||
func (bmj *BMCJob) HasCondition(cType BMCJobConditionType, cStatus ConditionStatus) bool { | ||
for _, c := range bmj.Status.Conditions { | ||
if c.Type == cType { | ||
return c.Status == cStatus | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
// FormatTaskName returns a BMCTask name based on BMCJob name. | ||
func FormatTaskName(job BMCJob, n int) string { | ||
return fmt.Sprintf("%s-task-%d", job.Name, n) | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
//+kubebuilder:resource:path=bmcjobs,scope=Namespaced,categories=tinkerbell,singular=bmcjob,shortName=bmj | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rufuio.tinkerbell.org