Skip to content

Commit

Permalink
Update first.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
hyfj44255 authored Aug 6, 2023
1 parent d798d1c commit cf39d88
Showing 1 changed file with 65 additions and 5 deletions.
70 changes: 65 additions & 5 deletions first.txt
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
}

0 comments on commit cf39d88

Please sign in to comment.