-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DatadogAgent reconcileV2 skeleton (#491)
* feat(controller): reconcileV2 function skeleton * new iteration * Update code after first local run * update after @celene review * fix ci error Co-authored-by: Celene Chang <celene@datadoghq.com>
- Loading branch information
1 parent
c32af59
commit cda69ab
Showing
41 changed files
with
1,328 additions
and
5,056 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package v2alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// UpdateDatadogAgentStatusConditionsFailure used to update the failure StatusConditions | ||
func UpdateDatadogAgentStatusConditionsFailure(status *DatadogAgentStatus, now metav1.Time, conditionType, reason, message string, err error) { | ||
if err != nil { | ||
UpdateDatadogAgentStatusConditions(status, now, conditionType, metav1.ConditionTrue, reason, fmt.Sprintf("msg:%s, err:%v", message, err), true) | ||
} else { | ||
UpdateDatadogAgentStatusConditions(status, now, conditionType, metav1.ConditionFalse, reason, message, true) | ||
} | ||
} | ||
|
||
// UpdateDatadogAgentStatusConditions used to update a specific string in conditions | ||
func UpdateDatadogAgentStatusConditions(status *DatadogAgentStatus, now metav1.Time, t string, conditionStatus metav1.ConditionStatus, reason, message string, writeFalseIfNotExist bool) { | ||
idConditionComplete := getIndexForConditionType(status, t) | ||
if idConditionComplete >= 0 { | ||
UpdateDatadogAgentStatusCondition(status.Conditions[idConditionComplete], now, t, conditionStatus, reason, message) | ||
} else if conditionStatus == metav1.ConditionTrue || writeFalseIfNotExist { | ||
// Only add if the condition is True | ||
status.Conditions = append(status.Conditions, NewDatadogAgentStatusCondition(t, conditionStatus, now, reason, message)) | ||
} | ||
} | ||
|
||
// UpdateDatadogAgentStatusCondition used to update a specific string | ||
func UpdateDatadogAgentStatusCondition(condition metav1.Condition, now metav1.Time, t string, conditionStatus metav1.ConditionStatus, reason, message string) metav1.Condition { | ||
if condition.Status != conditionStatus { | ||
condition.LastTransitionTime = now | ||
condition.Status = conditionStatus | ||
} | ||
condition.LastTransitionTime = now | ||
condition.Message = message | ||
condition.Reason = reason | ||
|
||
return condition | ||
} | ||
|
||
// SetDatadogAgentStatusCondition use to set a condition | ||
func SetDatadogAgentStatusCondition(status *DatadogAgentStatus, condition *metav1.Condition) { | ||
idConditionComplete := getIndexForConditionType(status, condition.Type) | ||
if idConditionComplete >= 0 { | ||
status.Conditions[idConditionComplete] = *condition | ||
} else { | ||
status.Conditions = append(status.Conditions, *condition) | ||
} | ||
} | ||
|
||
// NewDatadogAgentStatusCondition returns new DatadogAgentCondition instance | ||
func NewDatadogAgentStatusCondition(conditionType string, conditionStatus metav1.ConditionStatus, now metav1.Time, reason, message string) metav1.Condition { | ||
return metav1.Condition{ | ||
Type: conditionType, | ||
Status: conditionStatus, | ||
LastTransitionTime: now, | ||
Reason: reason, | ||
Message: message, | ||
} | ||
} | ||
|
||
func getIndexForConditionType(status *DatadogAgentStatus, t string) int { | ||
idCondition := -1 | ||
if status == nil { | ||
return idCondition | ||
} | ||
|
||
for i, condition := range status.Conditions { | ||
if condition.Type == t { | ||
idCondition = i | ||
break | ||
} | ||
} | ||
|
||
return idCondition | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package v2alpha1 | ||
|
||
const ( | ||
|
||
// ClusterAgentReconcileConditionType ReconcileConditionType for Cluster Agent component | ||
ClusterAgentReconcileConditionType = "ClusterAgentReconcile" | ||
// AgentReconcileConditionType ReconcileConditionType for Agent component | ||
AgentReconcileConditionType = "AgentReconcile" | ||
// ClusterCheckRunnerReconcileConditionType ReconcileConditionType for Cluster Check Runner component | ||
ClusterCheckRunnerReconcileConditionType = "ClusterCheckRunnerReconcile" | ||
// DatadogAgentReconcileErrorConditionType ReconcileConditionType for DatadogAgent reconcile error | ||
DatadogAgentReconcileErrorConditionType = "DatadogAgentReconcileError" | ||
) |
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.
Oops, something went wrong.