Go-based network automation with YANG models, gRPC, Ansible, Terraform, and Kubernetes integration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package underlay
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"go.uber.org/zap"
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/rest"
|
|
|
|
"github.com/guildhouse-co/kedge/internal/config"
|
|
"github.com/guildhouse-co/kedge/internal/quartermaster"
|
|
)
|
|
|
|
// Watcher watches for YANG instance data changes in ConfigMaps and triggers
|
|
// compilation and SDK dispatch for underlay device configuration.
|
|
type Watcher struct {
|
|
cfg config.UnderlayConfig
|
|
qm *quartermaster.Client
|
|
log *zap.SugaredLogger
|
|
clientset kubernetes.Interface
|
|
}
|
|
|
|
// NewWatcher creates a new underlay YANG watcher.
|
|
func NewWatcher(cfg config.UnderlayConfig, qm *quartermaster.Client, log *zap.SugaredLogger) *Watcher {
|
|
return &Watcher{cfg: cfg, qm: qm, log: log}
|
|
}
|
|
|
|
// Run starts watching for YANG instance data changes.
|
|
func (w *Watcher) Run(ctx context.Context) error {
|
|
if !w.cfg.Enabled {
|
|
w.log.Info("underlay mode disabled, watcher idle")
|
|
<-ctx.Done()
|
|
return nil
|
|
}
|
|
|
|
// Build in-cluster K8s client.
|
|
k8sConfig, err := rest.InClusterConfig()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get in-cluster config: %w", err)
|
|
}
|
|
w.clientset, err = kubernetes.NewForConfig(k8sConfig)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create k8s client: %w", err)
|
|
}
|
|
|
|
w.log.Infof("watching ConfigMap %s/%s for YANG instance data changes",
|
|
w.cfg.Namespace, w.cfg.ConfigMapName)
|
|
|
|
// TODO: Set up informer to watch ConfigMap for changes.
|
|
// On change: trigger YANG compilation, then dispatch SDK calls via Bascule.
|
|
// Each mutation is notarized via Quartermaster.
|
|
|
|
<-ctx.Done()
|
|
return nil
|
|
}
|