multiclusterprovider

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

multicluster-cloud-provider

This repository defines the shared interfaces which Karmada cloud providers implement. These interfaces allow various controllers to integrate with any cloud provider in a pluggable fashion.

Background

To enable Karmada to run on the public cloud platform and flexibly use and manage other basic resources and services on the cloud, cloud providers need to implement their own adapters. However, in the implementation process, some works are the same for each cloud provider.

Learn from the experience of Kubernetes Cloud Controller Manager (CCM): https://github.com/kubernetes/cloud-provider. Karmada can also provide a public repository that provides interfaces for using and managing basic resources and services on the public cloud. Cloud providers only need to implement these interfaces to provide users with their own adapters.

Purpose

This library is shared dependency for processes which need to be able to integrate with cloud provider specific functionality.

Fake testing

Command:

Make multicluster-provider-fake binary:

make multicluster-provider-fake

Make multicluster-provider-fake image:

make image-multicluster-provider-fake

Deploy multicluster-provider-fake deployment:

hack/deploy-provider.sh

Delete multicluster-provider-fake deployment :

kubectl --context karmada-host -n karmada-system delete deployments.apps multicluster-provider-fake
Verify
mci.yaml
apiVersion: networking.karmada.io/v1alpha1
kind: MultiClusterIngress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: serve
            port:
              number: 80
application.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: serve
spec:
  replicas: 1
  selector:
    matchLabels:
      app: serve
  template:
    metadata:
      labels:
        app: serve
    spec:
      containers:
      - name: serve
        image: jeremyot/serve:0a40de8
        args:
        - "--message='hello from cluster member1 (Node: {{env \"NODE_NAME\"}} Pod: {{env \"POD_NAME\"}} Address: {{addr}})'"
        env:
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
---
apiVersion: v1
kind: Service
metadata:
  name: serve
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: serve
---
apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: mcs-workload
spec:
  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
      name: serve
    - apiVersion: v1
      kind: Service
      name: serve
  placement:
    clusterAffinity:
      clusterNames:
        - member1
        - member2
    replicaScheduling:
      replicaDivisionPreference: Weighted
      replicaSchedulingType: Divided
      weightPreference:
        staticWeightList:
          - targetCluster:
              clusterNames:
                - member1
            weight: 1
          - targetCluster:
              clusterNames:
                - member2
            weight: 1
kubectl apply -f mci.yaml
kubectl apply -f application.yaml

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterMultiClusterProvider

func RegisterMultiClusterProvider(name string, cloudFactory Factory)

RegisterMultiClusterProvider registers a multiclusterprovider.Factory by name. This is expected to happen during app startup.

Types

type Factory

type Factory func(config io.Reader) (Interface, error)

Factory is a function that returns a multiclusterprovider.Interface. The config parameter provides an io.Reader handler to the factory in order to load specific configurations. If no configuration is provided the parameter is nil.

type Interface

type Interface interface {
	// LoadBalancer returns a MultiClusterIngress balancer interface, also returns true
	// if the interface is supported, false otherwise.
	LoadBalancer() (LoadBalancer, bool)
	// MCSLoadBalancer returns a MultiClusterService balancer interface, also returns true
	// if the interface is supported, false otherwise.
	MCSLoadBalancer() (MCSLoadBalancer, bool)
	// ProviderName returns the cloud provider ID.
	ProviderName() string
}

Interface is an abstract, pluggable interface for multcluster provider.

func InitMultiClusterProvider

func InitMultiClusterProvider(name string, configFilePath string) (Interface, error)

InitMultiClusterProvider creates an instance of the named multicluster provider.

type LoadBalancer

type LoadBalancer interface {
	// GetLoadBalancer return whether the specified load balancer exists, and if so, what its status is.
	GetLoadBalancer(ctx context.Context, mci *networkingv1alpha1.MultiClusterIngress) (status *networkingv1.IngressLoadBalancerStatus, exist bool, err error)
	// EnsureLoadBalancer creates a new load balancer.
	EnsureLoadBalancer(ctx context.Context, mci *networkingv1alpha1.MultiClusterIngress) (status *networkingv1.IngressLoadBalancerStatus, err error)
	// UpdateLoadBalancer updates the specified load balancer.
	UpdateLoadBalancer(ctx context.Context, mci *networkingv1alpha1.MultiClusterIngress) (status *networkingv1.IngressLoadBalancerStatus, err error)
	// EnsureLoadBalancerDeleted deletes the specified load balancer if it exists.
	EnsureLoadBalancerDeleted(ctx context.Context, mci *networkingv1alpha1.MultiClusterIngress) error
}

LoadBalancer is an abstract, pluggable interface for MultiClusterIngress load balancers.

type MCSLoadBalancer

type MCSLoadBalancer interface {
	// GetMCSLoadBalancer return whether the specified load balancer exists, and if so, what its status is.
	GetMCSLoadBalancer(ctx context.Context, mcs *networkingv1alpha1.MultiClusterService) (status *corev1.LoadBalancerStatus, exist bool, err error)
	// EnsureMCSLoadBalancer creates a new load balancer.
	EnsureMCSLoadBalancer(ctx context.Context, mcs *networkingv1alpha1.MultiClusterService) (status *corev1.LoadBalancerStatus, err error)
	// UpdateMCSLoadBalancer updates the specified load balancer.
	UpdateMCSLoadBalancer(ctx context.Context, mcs *networkingv1alpha1.MultiClusterService) (status *corev1.LoadBalancerStatus, err error)
	// EnsureMCSLoadBalancerDeleted deletes the specified load balancer if it exists.
	EnsureMCSLoadBalancerDeleted(ctx context.Context, mcs *networkingv1alpha1.MultiClusterService) error
}

MCSLoadBalancer is an abstract, pluggable interface for MultiClusterService load balancers.

Directories

Path Synopsis
cmd
Package fake is a test-double implementation of multiclusterprovider.Interface.
Package fake is a test-double implementation of multiclusterprovider.Interface.
pkg

Jump to

Keyboard shortcuts

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