-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,65 @@ | ||
!!hellow world!! | ||
see the difference! | ||
edit on git web. | ||
second row on github web! | ||
gege | ||
|
||
func (r *MyResourceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
|
||
// Get Kubernetes client | ||
client := r.Client | ||
nodes := &corev1.NodeList{} | ||
|
||
// List nodes | ||
if err := client.List(ctx, nodes); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// Print CPU and memory | ||
for _, node := range nodes.Items { | ||
cpu := node.Status.Capacity["cpu"] | ||
memory := node.Status.Capacity["memory"] | ||
log.Info("Node", "name", node.Name, "cpu", cpu, "memory", memory) | ||
} | ||
|
||
// Requeue | ||
return ctrl.Result{Requeue: true}, nil | ||
} | ||
|
||
|
||
go | ||
import ( | ||
"context" | ||
"time" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
discovery "k8s.io/api/discovery/v1beta1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/go-logr/logr" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
func (r *MyResourceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
|
||
logger := r.Log.WithValues("myresource", req.NamespacedName) | ||
|
||
// Get client | ||
client := r.Client | ||
|
||
// List nodes | ||
nodeList := &discovery.NodeList{} | ||
if err := client.List(ctx, nodeList); err != nil { | ||
logger.Error(err, "unable to list nodes") | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// Print CPU and memory for each node | ||
for _, node := range nodeList.Items { | ||
cpu := node.Status.Capacity.Cpu() | ||
memory := node.Status.Capacity.Memory() | ||
|
||
logger.Info("Node details", | ||
"Name", node.Name, | ||
"CPU", cpu.String(), | ||
"Memory", memory.String()) | ||
} | ||
|
||
// Requeue | ||
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil | ||
} |