Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions helm/bundles/cortex-nova/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ cortex-scheduling-controllers:
enabledTasks:
- nova-decisions-cleanup-task

# List: iterate over all api servers with the gvk and return a combined list.
# Get: iterate over all api server with the gvk and return the first result that is found.
# Create/Update/Delete: based on the content of the resource, match api server with labels and execute op only there.
# WatchesMulticluster: watch resource in all clusters with the gvk.
multicluster:
# These resources will be written into the home cluster if no match is found.
fallbacks:
- gvk: "cortex.cloud/v1alpha1/Decision"
- # ...
apiservers:
- host: "https://api.cc-b0-qa-de-1.ccloud.external.a-qa-de-200.soil-garden.qa-de-1.cloud.sap"
gvks: # Used for List, Get, Watches
- "cortex.cloud/v1alpha1/Decision"
- "cortex.cloud/v1alpha1/DecisionList"
# ...
labels: # Used for Create/Update/Delete
az: "qa-de-1b"

cortex-knowledge-controllers:
<<: *cortex
namePrefix: cortex-nova-knowledge
Expand Down
46 changes: 37 additions & 9 deletions pkg/multicluster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"errors"
"sync"

hv1 "github.com/cobaltcore-dev/openstack-hypervisor-operator/api/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -17,7 +18,40 @@
"sigs.k8s.io/controller-runtime/pkg/cluster"
)

type ResourceRouter interface {
Match(obj any, labels map[string]string) (bool, error)
}

type HypervisorResourceRouter struct{}

func (h HypervisorResourceRouter) Match(obj any, labels map[string]string) (bool, error) {
hv, ok := obj.(hv1.Hypervisor)
if !ok {
return false, errors.New("object is not a Hypervisor")
}
// Match by hypervisor availability zone label.
az, ok := labels["az"]
if !ok {
return false, errors.New("object does not have availability zone label")
}
hvAZ, ok := hv.Labels["topology.kubernetes.io/zone"]
if !ok {
return false, errors.New("hypervisor does not have availability zone label")
}
return hvAZ == az, nil
}

func main() {
_ = Client{
ResourceRouters: map[schema.GroupVersionKind]ResourceRouter{
hv1.GroupVersion.WithKind("Hypervisor"): HypervisorResourceRouter{},
},
}
}

type Client struct {
ResourceRouters map[schema.GroupVersionKind]ResourceRouter

// The cluster in which cortex is deployed.
HomeCluster cluster.Cluster
// The REST config for the home cluster in which cortex is deployed.
Expand Down Expand Up @@ -134,17 +168,11 @@
return gvks[0], nil
}

// Get the cluster for the given group version kind.
//
// If this object kind does not have a remote cluster configured,
// the home cluster is returned.
func (c *Client) ClusterForResource(gvk schema.GroupVersionKind) cluster.Cluster {
func (c *Client) ClusterForResource(routable Routable) cluster.Cluster {

Check failure on line 171 in pkg/multicluster/client.go

View workflow job for this annotation

GitHub Actions / test-without-docker

undefined: Routable

Check failure on line 171 in pkg/multicluster/client.go

View workflow job for this annotation

GitHub Actions / Checks

undefined: Routable (typecheck)

Check failure on line 171 in pkg/multicluster/client.go

View workflow job for this annotation

GitHub Actions / CodeQL

undefined: Routable) (typecheck)

Check failure on line 171 in pkg/multicluster/client.go

View workflow job for this annotation

GitHub Actions / Checks

undefined: Routable (typecheck)

Check failure on line 171 in pkg/multicluster/client.go

View workflow job for this annotation

GitHub Actions / test-without-docker

undefined: Routable

Check failure on line 171 in pkg/multicluster/client.go

View workflow job for this annotation

GitHub Actions / CodeQL

undefined: Routable) (typecheck)
c.remoteClustersMu.RLock()
defer c.remoteClustersMu.RUnlock()
cl, ok := c.remoteClusters[gvk]
if ok {
return cl
}
// TODO: Match the approprite cluster.

return c.HomeCluster
}

Expand Down
Loading