Skip to content

Commit

Permalink
clustermesh: Add helper functions to set/get cluster configuration
Browse files Browse the repository at this point in the history
Add hepler functions to set/get cluster information on kvstore.

Signed-off-by: Yutaro Hayakawa <yutaro.hayakawa@isovalent.com>
  • Loading branch information
YutaroHayakawa authored and pchaigno committed Dec 12, 2022
1 parent 857060b commit b24973e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/clustermesh/clustermesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ package clustermesh

import (
"context"
"encoding/json"
"fmt"
"path"
"time"

"github.com/prometheus/client_golang/prometheus"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/allocator"
cmtypes "github.com/cilium/cilium/pkg/clustermesh/types"
"github.com/cilium/cilium/pkg/controller"
"github.com/cilium/cilium/pkg/ipcache"
"github.com/cilium/cilium/pkg/kvstore"
Expand Down Expand Up @@ -73,6 +76,43 @@ type Configuration struct {
NodesSharedKeyDeleteDelay *time.Duration
}

func SetClusterConfig(clusterName string, config *cmtypes.CiliumClusterConfig, backend kvstore.BackendOperations) error {
key := path.Join(kvstore.ClusterConfigPrefix, clusterName)

val, err := json.Marshal(config)
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

_, err = kvstore.Client().UpdateIfDifferent(ctx, key, val, true)
if err != nil {
return err
}

return nil
}

func GetClusterConfig(clusterName string, backend kvstore.BackendOperations) (*cmtypes.CiliumClusterConfig, error) {
var config cmtypes.CiliumClusterConfig

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

val, err := backend.Get(ctx, path.Join(kvstore.ClusterConfigPrefix, clusterName))
if err != nil {
return nil, err
}

if err := json.Unmarshal(val, &config); err != nil {
return nil, err
}

return &config, nil
}

// RemoteIdentityWatcher is any type which provides identities that have been
// allocated on a remote cluster.
type RemoteIdentityWatcher interface {
Expand Down

0 comments on commit b24973e

Please sign in to comment.