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

[CECO-570] Add operator introspection #817

Merged
merged 24 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2311579
Add operator introspection
khewonc Jun 7, 2023
07331db
Send reconcile request when provider added or deleted
khewonc Jun 22, 2023
e82b27f
Merge branch 'main' into khewonc/introspection
khewonc Aug 14, 2023
49877c1
Merge branch 'main' into khewonc/introspection
khewonc Sep 6, 2023
12e7092
introspection v2
khewonc Sep 6, 2023
a0fb702
Merge branch 'main' into khewonc/introspection
khewonc Sep 11, 2023
6e632a2
Change local agent service selector
khewonc Sep 11, 2023
1f1403f
Merge branch 'main' into khewonc/introspection
khewonc Oct 11, 2023
01def37
Suggestions from code review
khewonc Oct 11, 2023
be66ae2
Cleanup unused options
khewonc Oct 11, 2023
c6382de
Simplify providers struct
khewonc Oct 23, 2023
6e6d537
Merge branch 'main' into khewonc/introspection
khewonc Oct 24, 2023
70219e1
Fix stale status
khewonc Nov 7, 2023
cbaa0f0
Merge branch 'main' into khewonc/introspection
khewonc Nov 7, 2023
dd28d7f
Update after merging main
khewonc Nov 7, 2023
3bf8002
[CECO-754][introspection] Clean up unused ds/eds (#1014)
khewonc Dec 21, 2023
d4723ef
[CECO-755][introspection] Limit provider values using allowlist (#1021)
khewonc Dec 22, 2023
d5989da
[CECO-849][introspection] Remove unused ds status (#1023)
khewonc Dec 29, 2023
bade2df
Review suggestions
khewonc Jan 2, 2024
3bb1ccb
Merge branch 'main' into khewonc/introspection
khewonc Jan 2, 2024
9cb824f
Fix capitalisation in types
khewonc Jan 2, 2024
3975dfc
[introspection] Add flag, fix types, override name (#1035)
khewonc Jan 9, 2024
c369113
Merge branch 'main' into khewonc/introspection
khewonc Jan 9, 2024
553d24b
Adding LegacyProvider label to daemonset if introspection is disabled
Jan 11, 2024
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
2 changes: 2 additions & 0 deletions apis/datadoghq/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
AgentDeploymentNameLabelKey = "agent.datadoghq.com/name"
// AgentDeploymentComponentLabelKey label key use to know with component is it
AgentDeploymentComponentLabelKey = "agent.datadoghq.com/component"
// MD5AgentDeploymentProfileHashLabelKey label key is used to identify which profile was used to generate it
MD5AgentDeploymentProfileHashLabelKey = "agent.datadoghq.com/profilehash"
khewonc marked this conversation as resolved.
Show resolved Hide resolved
// MD5AgentDeploymentAnnotationKey annotation key used on a Resource in order to identify which AgentDeployment have been used to generate it.
MD5AgentDeploymentAnnotationKey = "agent.datadoghq.com/agentspechash"
// MD5ChecksumAnnotationKey annotation key is used to identify customConfig configurations
Expand Down
152 changes: 122 additions & 30 deletions apis/datadoghq/v2alpha1/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,74 +155,166 @@ func UpdateDeploymentStatus(dep *appsv1.Deployment, depStatus *commonv1.Deployme
}

// UpdateDaemonSetStatus updates a daemonset's DaemonSetStatus
func UpdateDaemonSetStatus(ds *appsv1.DaemonSet, dsStatus *commonv1.DaemonSetStatus, updateTime *metav1.Time) *commonv1.DaemonSetStatus {
func UpdateDaemonSetStatus(ds *appsv1.DaemonSet, dsStatus []*commonv1.DaemonSetStatus, updateTime *metav1.Time) []*commonv1.DaemonSetStatus {
if dsStatus == nil {
dsStatus = &commonv1.DaemonSetStatus{}
dsStatus = []*commonv1.DaemonSetStatus{}
}
if ds == nil {
dsStatus.State = string(DatadogAgentStateFailed)
dsStatus.Status = string(DatadogAgentStateFailed)
dsStatus = append(dsStatus, &commonv1.DaemonSetStatus{
State: string(DatadogAgentStateFailed),
Status: string(DatadogAgentStateFailed),
})
return dsStatus
}

newStatus := commonv1.DaemonSetStatus{
Desired: ds.Status.DesiredNumberScheduled,
Current: ds.Status.CurrentNumberScheduled,
Ready: ds.Status.NumberReady,
Available: ds.Status.NumberAvailable,
UpToDate: ds.Status.UpdatedNumberScheduled,
DaemonsetName: ds.ObjectMeta.Name,
}

if updateTime != nil {
dsStatus.LastUpdate = updateTime
newStatus.LastUpdate = updateTime
}
if hash, ok := ds.Annotations[apicommon.MD5AgentDeploymentAnnotationKey]; ok {
dsStatus.CurrentHash = hash
newStatus.CurrentHash = hash
}
dsStatus.Desired = ds.Status.DesiredNumberScheduled
dsStatus.Current = ds.Status.CurrentNumberScheduled
dsStatus.Ready = ds.Status.NumberReady
dsStatus.Available = ds.Status.NumberAvailable
dsStatus.UpToDate = ds.Status.UpdatedNumberScheduled

var deploymentState DatadogAgentState
switch {
case dsStatus.UpToDate != dsStatus.Desired:
case newStatus.UpToDate != newStatus.Desired:
deploymentState = DatadogAgentStateUpdating
case dsStatus.Ready == 0:
case newStatus.Ready == 0:
deploymentState = DatadogAgentStateProgressing
default:
deploymentState = DatadogAgentStateRunning
}

dsStatus.State = fmt.Sprintf("%v", deploymentState)
dsStatus.Status = fmt.Sprintf("%v (%d/%d/%d)", deploymentState, dsStatus.Desired, dsStatus.Ready, dsStatus.UpToDate)
dsStatus.DaemonsetName = ds.ObjectMeta.Name
newStatus.State = fmt.Sprintf("%v", deploymentState)
newStatus.Status = fmt.Sprintf("%v (%d/%d/%d)", deploymentState, newStatus.Desired, newStatus.Ready, newStatus.UpToDate)

// match ds name to ds status
found := false
for id := range dsStatus {
if dsStatus[id].DaemonsetName == newStatus.DaemonsetName {
*dsStatus[id] = newStatus
found = true
}
}
if !found {
dsStatus = append(dsStatus, &newStatus)
}

return dsStatus
}

// UpdateExtendedDaemonSetStatus updates an ExtendedDaemonSet's DaemonSetStatus
func UpdateExtendedDaemonSetStatus(eds *edsdatadoghqv1alpha1.ExtendedDaemonSet, dsStatus *commonv1.DaemonSetStatus, updateTime *metav1.Time) *commonv1.DaemonSetStatus {
func UpdateExtendedDaemonSetStatus(eds *edsdatadoghqv1alpha1.ExtendedDaemonSet, dsStatus []*commonv1.DaemonSetStatus, updateTime *metav1.Time) []*commonv1.DaemonSetStatus {
if dsStatus == nil {
dsStatus = &commonv1.DaemonSetStatus{}
dsStatus = []*commonv1.DaemonSetStatus{}
}

newStatus := commonv1.DaemonSetStatus{
Desired: eds.Status.Desired,
Current: eds.Status.Current,
Ready: eds.Status.Ready,
Available: eds.Status.Available,
UpToDate: eds.Status.UpToDate,
DaemonsetName: eds.ObjectMeta.Name,
}

if updateTime != nil {
dsStatus.LastUpdate = updateTime
newStatus.LastUpdate = updateTime
}
if hash, ok := eds.Annotations[apicommon.MD5AgentDeploymentAnnotationKey]; ok {
dsStatus.CurrentHash = hash
newStatus.CurrentHash = hash
}
dsStatus.Desired = eds.Status.Desired
dsStatus.Current = eds.Status.Current
dsStatus.Ready = eds.Status.Ready
dsStatus.Available = eds.Status.Available
dsStatus.UpToDate = eds.Status.UpToDate

var deploymentState DatadogAgentState
switch {
case eds.Status.Canary != nil:
deploymentState = DatadogAgentStateCanary
case dsStatus.UpToDate != dsStatus.Desired:
case newStatus.UpToDate != newStatus.Desired:
deploymentState = DatadogAgentStateUpdating
case dsStatus.Ready == 0:
case newStatus.Ready == 0:
deploymentState = DatadogAgentStateProgressing
default:
deploymentState = DatadogAgentStateRunning
}

dsStatus.State = fmt.Sprintf("%v", deploymentState)
dsStatus.Status = fmt.Sprintf("%v (%d/%d/%d)", deploymentState, dsStatus.Desired, dsStatus.Ready, dsStatus.UpToDate)
dsStatus.DaemonsetName = eds.ObjectMeta.Name
newStatus.State = fmt.Sprintf("%v", deploymentState)
newStatus.Status = fmt.Sprintf("%v (%d/%d/%d)", deploymentState, newStatus.Desired, newStatus.Ready, newStatus.UpToDate)

// match eds name to eds status
found := false
for id := range dsStatus {
if dsStatus[id].DaemonsetName == newStatus.DaemonsetName {
*dsStatus[id] = newStatus
found = true
}
}
if !found {
dsStatus = append(dsStatus, &newStatus)
}

return dsStatus
}

// UpdateCombinedDaemonSetStatus combines the status of multiple DaemonSetStatus
func UpdateCombinedDaemonSetStatus(dsStatus []*commonv1.DaemonSetStatus) *commonv1.DaemonSetStatus {
combinedStatus := commonv1.DaemonSetStatus{}
if len(dsStatus) == 0 {
return &combinedStatus
}

for _, status := range dsStatus {
combinedStatus.Desired += status.Desired
combinedStatus.Current += status.Current
combinedStatus.Ready += status.Ready
combinedStatus.Available += status.Available
combinedStatus.UpToDate += status.UpToDate
if combinedStatus.LastUpdate.Before(status.LastUpdate) {
combinedStatus.LastUpdate = status.LastUpdate
}
combinedStatus.State = getCombinedState(combinedStatus.State, status.State)
combinedStatus.Status = fmt.Sprintf("%v (%d/%d/%d)", combinedStatus.State, combinedStatus.Desired, combinedStatus.Ready, combinedStatus.UpToDate)
}

return &combinedStatus
}

func getCombinedState(currentState, newState string) string {
currentNum := assignNumeralState(currentState)
newNum := assignNumeralState(newState)

if currentNum == 0 {
return newState
}
if newNum == 0 {
return currentState
}
if currentNum < newNum {
return currentState
}
return newState
}

func assignNumeralState(state string) int {
switch state {
case string(DatadogAgentStateFailed):
return 1
case string(DatadogAgentStateCanary):
return 2
case string(DatadogAgentStateUpdating):
return 3
case string(DatadogAgentStateProgressing):
return 4
case string(DatadogAgentStateRunning):
return 5
default:
return 0
}
}
11 changes: 8 additions & 3 deletions apis/datadoghq/v2alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,14 @@ type DatadogAgentStatus struct {
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions"`
// The actual state of the Agent as an extended daemonset.
// The actual state of the Agent as a daemonset or an extended daemonset.
// +optional
Agent *commonv1.DaemonSetStatus `json:"agent,omitempty"`
// +listType=map
// +listMapKey=desired
Agent []*commonv1.DaemonSetStatus `json:"agent,omitempty"`
// The combined actual state of the all Agent as daemonsets or extended daemonsets.
// +optional
CombinedAgent *commonv1.DaemonSetStatus `json:"combinedAgent,omitempty"`
khewonc marked this conversation as resolved.
Show resolved Hide resolved
// The actual state of the Cluster Agent as a deployment.
// +optional
ClusterAgent *commonv1.DeploymentStatus `json:"clusterAgent,omitempty"`
Expand All @@ -1065,7 +1070,7 @@ type DatadogAgentStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:resource:path=datadogagents,shortName=dd
// +kubebuilder:printcolumn:name="agent",type="string",JSONPath=".status.agent.status"
// +kubebuilder:printcolumn:name="agent",type="string",JSONPath=".status.combinedAgent.status"
// +kubebuilder:printcolumn:name="cluster-agent",type="string",JSONPath=".status.clusterAgent.status"
// +kubebuilder:printcolumn:name="cluster-checks-runner",type="string",JSONPath=".status.clusterChecksRunner.status"
// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp"
Expand Down
11 changes: 11 additions & 0 deletions apis/datadoghq/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion apis/datadoghq/v2alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/kubectl-datadog/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (o *options) runV2() error {
func (o *options) renderTable(statuses []common.StatusWrapper) {
table := newTable(o.Out)
for _, item := range statuses {
data := []string{item.GetObjectMeta().GetName(), item.GetObjectMeta().GetNamespace()}
data := []string{item.GetObjectMeta().GetNamespace(), item.GetObjectMeta().GetName()}
if item.GetAgentStatus() != nil {
data = append(data, item.GetAgentStatus().Status)
} else {
Expand Down
Loading