MCPcopy
hub / github.com/apecloud/kubeblocks / isHostNetworkEnabled

Function isHostNetworkEnabled

pkg/controller/component/utils.go:106–136  ·  view source on GitHub ↗
(ctx context.Context, cli client.Reader, synthesizedComp *SynthesizedComponent, compName string)

Source from the content-addressed store, hash-verified

104}
105
106func isHostNetworkEnabled(ctx context.Context, cli client.Reader, synthesizedComp *SynthesizedComponent, compName string) (bool, error) {
107 // fast path: refer to self
108 if compName == synthesizedComp.Name {
109 return IsHostNetworkEnabled(synthesizedComp), nil
110 }
111
112 // check the component object that whether the host-network is enabled
113 compKey := types.NamespacedName{
114 Namespace: synthesizedComp.Namespace,
115 Name: constant.GenerateClusterComponentName(synthesizedComp.ClusterName, compName),
116 }
117 comp := &appsv1.Component{}
118 if err := cli.Get(ctx, compKey, comp, inDataContext()); err != nil {
119 return false, err
120 }
121 if !hasHostNetworkEnabled(comp.Annotations, compName) {
122 return false, nil
123 }
124
125 // check the component definition that whether it has the host-network capability
126 if len(comp.Spec.CompDef) > 0 {
127 compDef := &appsv1.ComponentDefinition{}
128 if err := cli.Get(ctx, types.NamespacedName{Name: comp.Spec.CompDef}, compDef); err != nil {
129 return false, err
130 }
131 if hasHostNetworkCapability(nil, compDef) {
132 return true, nil
133 }
134 }
135 return false, nil
136}
137
138func hasHostNetworkCapability(synthesizedComp *SynthesizedComponent, compDef *appsv1.ComponentDefinition) bool {
139 switch {

Callers 1

Calls 6

IsHostNetworkEnabledFunction · 0.85
hasHostNetworkEnabledFunction · 0.85
hasHostNetworkCapabilityFunction · 0.85
inDataContextFunction · 0.70
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…