Skip to content

Commit

Permalink
chore: hostNetwork supports sharding (#8517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie authored Nov 27, 2024
1 parent 6d24aca commit ace137f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 17 additions & 0 deletions controllers/apps/transformer_cluster_api_normalization.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ package apps
import (
"fmt"
"maps"
"strings"

"golang.org/x/exp/slices"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -217,6 +219,21 @@ func (t *ClusterAPINormalizationTransformer) buildCompAnnotationsInheritedFromCl
for _, compSpec := range transCtx.ComponentSpecs {
annotations[compSpec.Name] = maps.Clone(clusterAnnotations)
}

// covert the sharding hostNetwork annotation to the component annotation
hnShardingOrComps, ok := cluster.Annotations[constant.HostNetworkAnnotationKey]
if !ok {
return annotations
}

hnShardingOrCompList := strings.Split(hnShardingOrComps, ",")
for _, sharding := range cluster.Spec.ShardingSpecs {
if slices.Index(hnShardingOrCompList, sharding.Name) >= 0 {
for _, compSpec := range transCtx.ShardingComponentSpecs[sharding.Name] {
annotations[compSpec.Name][constant.HostNetworkAnnotationKey] = compSpec.Name
}
}
}
return annotations
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/component/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ func hasHostNetworkCapability(synthesizedComp *SynthesizedComponent, compDef *ap
}

func hasHostNetworkEnabled(annotations map[string]string, compName string) bool {
if annotations == nil {
return false
}
comps, ok := annotations[constant.HostNetworkAnnotationKey]
if !ok {
return false
Expand Down

0 comments on commit ace137f

Please sign in to comment.