-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add status handlers for dcgm and neuron (#169)
- Loading branch information
Showing
6 changed files
with
135 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package dcgmexporter | ||
|
||
import ( | ||
"context" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1" | ||
"github.com/aws/amazon-cloudwatch-agent-operator/internal/version" | ||
) | ||
|
||
func UpdateDcgmExporterStatus(ctx context.Context, cli client.Client, changed *v1alpha1.DcgmExporter) error { | ||
if changed.Status.Version == "" { | ||
changed.Status.Version = version.DcgmExporter() | ||
} | ||
|
||
return nil | ||
} |
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,44 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package dcgmexporter | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/go-logr/logr" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests" | ||
) | ||
|
||
const ( | ||
eventTypeNormal = "Normal" | ||
eventTypeWarning = "Warning" | ||
|
||
reasonError = "Error" | ||
reasonStatusFailure = "StatusFailure" | ||
reasonInfo = "Info" | ||
) | ||
|
||
func HandleReconcileStatus(ctx context.Context, log logr.Logger, params manifests.Params, err error) (ctrl.Result, error) { | ||
log.V(2).Info("updating dcgmexporter status") | ||
if err != nil { | ||
params.Recorder.Event(¶ms.OtelCol, eventTypeWarning, reasonError, err.Error()) | ||
return ctrl.Result{}, err | ||
} | ||
changed := params.DcgmExp.DeepCopy() | ||
statusErr := UpdateDcgmExporterStatus(ctx, params.Client, changed) | ||
if statusErr != nil { | ||
params.Recorder.Event(changed, eventTypeWarning, reasonStatusFailure, statusErr.Error()) | ||
return ctrl.Result{}, statusErr | ||
} | ||
statusPatch := client.MergeFrom(¶ms.DcgmExp) | ||
if err := params.Client.Status().Patch(ctx, changed, statusPatch); err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to apply status changes to the DcgmExporter CR: %w", err) | ||
} | ||
params.Recorder.Event(changed, eventTypeNormal, reasonInfo, "applied status changes") | ||
return ctrl.Result{}, nil | ||
} |
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,44 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package neuronmonitor | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/go-logr/logr" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests" | ||
) | ||
|
||
const ( | ||
eventTypeNormal = "Normal" | ||
eventTypeWarning = "Warning" | ||
|
||
reasonError = "Error" | ||
reasonStatusFailure = "StatusFailure" | ||
reasonInfo = "Info" | ||
) | ||
|
||
func HandleReconcileStatus(ctx context.Context, log logr.Logger, params manifests.Params, err error) (ctrl.Result, error) { | ||
log.V(2).Info("updating neuronmonitor status") | ||
if err != nil { | ||
params.Recorder.Event(¶ms.NeuronExp, eventTypeWarning, reasonError, err.Error()) | ||
return ctrl.Result{}, err | ||
} | ||
changed := params.NeuronExp.DeepCopy() | ||
statusErr := UpdateNeuronMonitorStatus(ctx, params.Client, changed) | ||
if statusErr != nil { | ||
params.Recorder.Event(changed, eventTypeWarning, reasonStatusFailure, statusErr.Error()) | ||
return ctrl.Result{}, statusErr | ||
} | ||
statusPatch := client.MergeFrom(¶ms.NeuronExp) | ||
if err := params.Client.Status().Patch(ctx, changed, statusPatch); err != nil { | ||
return ctrl.Result{}, fmt.Errorf("failed to apply status changes to the NeuronMonitor CR: %w", err) | ||
} | ||
params.Recorder.Event(changed, eventTypeNormal, reasonInfo, "applied status changes") | ||
return ctrl.Result{}, nil | ||
} |
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,20 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package neuronmonitor | ||
|
||
import ( | ||
"context" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1" | ||
"github.com/aws/amazon-cloudwatch-agent-operator/internal/version" | ||
) | ||
|
||
func UpdateNeuronMonitorStatus(ctx context.Context, cli client.Client, changed *v1alpha1.NeuronMonitor) error { | ||
if changed.Status.Version == "" { | ||
changed.Status.Version = version.NeuronMonitor() | ||
} | ||
return nil | ||
} |