edgewatcher

package module
v0.0.0-...-ec93226 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 14 Imported by: 8

README

WARNING: This repository is published by the Nephio Authors but is neither endorsed nor maintained by the Nephio Technical Steering Committee (TSC). It is intended to be used for reference only. The Nephio distribution repositories are located in the nephio-project organization. For more information see this page.

EdgeWatcher

EdgeWatcher is a gRPC server which receives the current serialized state of Kubernetes objects from the WatcherAgent. It also exposes events for client (an example of a client is the deployment entity of NFDeploy Controller to subscribe to in getting status updates.

Description

EdgeWatcher

EdgeWatcher is a library which consists of a gRPC server to receive statuses from WatcherAgent from each of the workload clusters. It is currently utilized by the NFDeployment controller, where upon processing the NFDeployment CR, the deployment entity would create a gRPC server instance, and EdgeWatcher would be running to wait for a creation of a workload cluster (or just go through a list of currently running workload cluster), and sends a WatcherAgent CR to WatcherAgent running on the workload cluster. This CR will inform the resources which EdgeWatcher is requesting this WatcherAgent to watch, and the gRPC endpoint where that WatcherAgent will send status update to. EdgeWatcher also exposes a List/Watch Interface for client to subscribe to such that the client would be able to watch XXXDeployment objects on workload cluster. The following diagram depicts the relationship between EdgeWatcher and its client, and the WatcherAgents running on workload cluster:

EdgeWatcher and its relationship with client and WatcherAgents

Getting Started

EdgeWatcher is a go module, build EdgeWatcher via:

make build
from the client
  1. import the EdgeWatcher module:
import (
  edgewatcher "github.com/nephio-project/edge-watcher"
)
  1. instantiate the EdgeWatcher instance (as an example):
var edgeWatcherConfig edgewatcher.Params
edgeWatcherConfig.K8sDynamicClient, err = dynamic.NewForConfig(mgr.GetConfig())
edgeWatcherConfig.PorchClient = porch.NewClient(ctrl.Log.WithName("PorchClient"),
        porchclient, k8sRestClient)
edgeWatcherConfig.GRPCServer = grpc.NewServer(grpcOpts...)
ep, err := edgewatcher.New(ctx, edgewatcherLogger, edgeWatcherConfig,)

NOTE: client does have to manually run the gRPC server:

   go func() {
        err := edgeWatcherConfig.GRPCServer.Serve(lis)
        if err != nil {
            setupLog.Error(err, "starting grpc server failed")
            os.Exit(1)
        }
    }()
  1. Client then can subscribe to a particular event
subscribeReq := edgewatcher.SubscriptionReq{
...
}
Uninstall CRDs

To delete the CRDs from the cluster:

make uninstall
Undeploy controller

UnDeploy the controller to the cluster:

make undeploy

Contributing

// TODO: Add detailed information on how you would like others to contribute to this project

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventOptions

type EventOptions struct {
	Type SubscriptionType
	// The name of the subscriptionType, which could be a clusterName or NFDeploy
	// name.
	SubscriptionName string
}

EventOptions is used for filtering the edge events based on either cluster or parent NfDeploy

type EventPublisher

type EventPublisher interface {
	// Subscribe returns a channel to receive SubscriptionReq from clients
	Subscribe() chan *SubscriptionReq
	// Cancel returns a channel to receive cancellation request in form of
	// SubscriptionReq from clients. Request should have SubscriptionReq.Ctx,
	// SubscriptionReq.Error and SubscriptionReq.SubscriberInfo.SubscriberName.
	Cancel() chan *SubscriptionReq
}

EventPublisher publishes k8s events received from the edgeclusters. It allows the clients to subscribe to events using SubscriptionReq.

func New

func New(ctx context.Context, logger logr.Logger, params Params) (EventPublisher, error)

New initializes and registers EdgeWatcherService with the given grpc.Server

type Params

type Params struct {
	GRPCServer           *grpc.Server      `ignored:"true"`
	K8sDynamicClient     dynamic.Interface `ignored:"true"`
	PorchClient          porch.Client      `ignored:"true"`
	PodIP                string            `required:"true" envconfig:"POD_IP"`
	Port                 string            `required:"true" envconfig:"GRPC_PORT"`
	NephioNamespace      string            `required:"true" envconfig:"NEPHIO_NAMESPACE"`
	EdgeClusterNamespace string            `required:"true" split_words:"true"`
}

type Router

type Router struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

Router maintains subscriptions for receiving events

func NewRouter

func NewRouter(logger logr.Logger, ctx context.Context) *Router

NewRouter returns an initialised Router object which can accept subscriptions to get events

func (*Router) Cancel

func (router *Router) Cancel() chan *SubscriptionReq

func (*Router) RouteEvent

func (router *Router) RouteEvent(key preprocessor.RequestKey) (
	stream chan *preprocessor.EventMessage)

RouteEvent returns the appropriate channel for sending the events to the router based on the RequestKey

func (*Router) Subscribe

func (router *Router) Subscribe() chan *SubscriptionReq

type SubscriberInfo

type SubscriberInfo struct {
	// SubscriberName is used for uniquely identifying the subscriber
	SubscriberName string
	// Channel is used for sending the preprocessor.Event to the subscriber
	Channel chan preprocessor.Event
	// contains filtered or unexported fields
}

SubscriberInfo uniquely identifies a subscriber

type SubscriptionReq

type SubscriptionReq struct {
	Ctx context.Context
	// Error is used to send any non-retryable error occurred during the
	// subscription/cancellation process and nil is sent in case of successful
	// subscription/cancellation.
	Error chan error

	EventOptions
	SubscriberInfo
}

type SubscriptionType

type SubscriptionType string
const (
	ClusterSubscriber  SubscriptionType = "clusterSubscriber"
	NfDeploySubscriber SubscriptionType = "nfdeploySubscriber"
)

Directories

Path Synopsis
tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL