add composite provider
Signed-off-by: Megrez Lu <lujiajing1126@gmail.com>
This commit is contained in:
parent
f0363f28c0
commit
94e012a930
|
@ -336,8 +336,9 @@ func (m *Manager) PatchStableService(c *TrafficRoutingContext) (bool, error) {
|
|||
|
||||
func newNetworkProvider(c client.Client, con *TrafficRoutingContext, sService, cService string) (network.NetworkProvider, error) {
|
||||
trafficRouting := con.ObjectRef[0]
|
||||
networkProviders := make([]network.NetworkProvider, 0, 3)
|
||||
if trafficRouting.CustomNetworkRefs != nil {
|
||||
return custom.NewCustomController(c, custom.Config{
|
||||
np, innerErr := custom.NewCustomController(c, custom.Config{
|
||||
Key: con.Key,
|
||||
RolloutNs: con.Namespace,
|
||||
CanaryService: cService,
|
||||
|
@ -347,9 +348,13 @@ func newNetworkProvider(c client.Client, con *TrafficRoutingContext, sService, c
|
|||
//only set for CustomController, never work for Ingress and Gateway
|
||||
DisableGenerateCanaryService: con.DisableGenerateCanaryService,
|
||||
})
|
||||
if innerErr != nil {
|
||||
return nil, innerErr
|
||||
}
|
||||
networkProviders = append(networkProviders, np)
|
||||
}
|
||||
if trafficRouting.Ingress != nil {
|
||||
return ingress.NewIngressTrafficRouting(c, ingress.Config{
|
||||
np, innerErr := ingress.NewIngressTrafficRouting(c, ingress.Config{
|
||||
Key: con.Key,
|
||||
Namespace: con.Namespace,
|
||||
CanaryService: cService,
|
||||
|
@ -357,17 +362,30 @@ func newNetworkProvider(c client.Client, con *TrafficRoutingContext, sService, c
|
|||
TrafficConf: trafficRouting.Ingress,
|
||||
OwnerRef: con.OwnerRef,
|
||||
})
|
||||
if innerErr != nil {
|
||||
return nil, innerErr
|
||||
}
|
||||
networkProviders = append(networkProviders, np)
|
||||
}
|
||||
if trafficRouting.Gateway != nil {
|
||||
return gateway.NewGatewayTrafficRouting(c, gateway.Config{
|
||||
np, innerErr := gateway.NewGatewayTrafficRouting(c, gateway.Config{
|
||||
Key: con.Key,
|
||||
Namespace: con.Namespace,
|
||||
CanaryService: cService,
|
||||
StableService: sService,
|
||||
TrafficConf: trafficRouting.Gateway,
|
||||
})
|
||||
if innerErr != nil {
|
||||
return nil, innerErr
|
||||
}
|
||||
networkProviders = append(networkProviders, np)
|
||||
}
|
||||
return nil, fmt.Errorf("TrafficRouting current only support Ingress or Gateway API")
|
||||
if len(networkProviders) == 0 {
|
||||
return nil, fmt.Errorf("TrafficRouting current only supports Ingress, Gateway API and CustomNetworkRefs")
|
||||
} else if len(networkProviders) == 1 {
|
||||
return networkProviders[0], nil
|
||||
}
|
||||
return network.CompositeController(networkProviders), nil
|
||||
}
|
||||
|
||||
func (m *Manager) createCanaryService(c *TrafficRoutingContext, cService string, spec corev1.ServiceSpec) (*corev1.Service, error) {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
Copyright 2024 The Kruise Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package network
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"github.com/openkruise/rollouts/api/v1beta1"
|
||||
)
|
||||
|
||||
var (
|
||||
_ NetworkProvider = (CompositeController)(nil)
|
||||
)
|
||||
|
||||
type CompositeController []NetworkProvider
|
||||
|
||||
func (c CompositeController) Initialize(ctx context.Context) error {
|
||||
var err error
|
||||
for _, provider := range c {
|
||||
err = multierr.Append(err, provider.Initialize(ctx))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c CompositeController) EnsureRoutes(ctx context.Context, strategy *v1beta1.TrafficRoutingStrategy) (bool, error) {
|
||||
done := true
|
||||
for _, provider := range c {
|
||||
innerDone, innerErr := provider.EnsureRoutes(ctx, strategy)
|
||||
if innerErr != nil {
|
||||
return false, innerErr
|
||||
}
|
||||
done = done && !innerDone
|
||||
}
|
||||
return done, nil
|
||||
}
|
||||
|
||||
func (c CompositeController) Finalise(ctx context.Context) error {
|
||||
var err error
|
||||
for _, provider := range c {
|
||||
err = multierr.Append(err, provider.Finalise(ctx))
|
||||
}
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue