MCPcopy
hub / github.com/fluid-cloudnative/fluid / inject

Method inject

pkg/application/inject/fuse/injector.go:75–235  ·  view source on GitHub ↗

inject takes the following steps to inject fuse container: 1. Determine the type of the input runtime.Object and wrap it as a FluidApplication which contains one or more PodSpecs. 2. For each PodSpec in the FluidApplication, and for each runtimeInfo involved, inject the PodSpec according to the runt

(in runtime.Object, runtimeInfos map[string]base.RuntimeInfoInterface)

Source from the content-addressed store, hash-verified

73// 4. Add injection done label to the PodSpec, indicating mutation is done for the PodSpec.
74// 5. When all the PodSpecs are mutated, return the modified runtime.Object
75func (s *Injector) inject(in runtime.Object, runtimeInfos map[string]base.RuntimeInfoInterface) (out runtime.Object, err error) {
76 out = in.DeepCopyObject()
77
78 var (
79 application common.FluidApplication
80 objectMeta metav1.ObjectMeta
81 typeMeta metav1.TypeMeta
82 )
83
84 // Handle Lists
85 if list, ok := out.(*corev1.List); ok {
86 result := list
87
88 for i, item := range list.Items {
89 obj, err := utils.FromRawToObject(item.Raw)
90 if runtime.IsNotRegisteredError(err) {
91 continue
92 }
93 if err != nil {
94 return nil, err
95 }
96
97 r, err := s.inject(obj, runtimeInfos)
98 if err != nil {
99 return nil, err
100 }
101
102 re := runtime.RawExtension{}
103 re.Object = r
104 result.Items[i] = re
105 }
106 return result, nil
107 }
108
109 switch v := out.(type) {
110 case *corev1.Pod:
111 pod := v
112 typeMeta = pod.TypeMeta
113 objectMeta = pod.ObjectMeta
114 application = podapp.NewApplication(pod)
115 case *unstructuredtype.Unstructured:
116 obj := v
117 typeMeta = metav1.TypeMeta{
118 Kind: obj.GetKind(),
119 APIVersion: obj.GetAPIVersion(),
120 }
121 objectMeta = metav1.ObjectMeta{
122 Name: obj.GetName(),
123 Namespace: obj.GetNamespace(),
124 Annotations: obj.GetAnnotations(),
125 Labels: obj.GetLabels(),
126 }
127 application = unstructured.NewApplication(obj)
128 case runtime.Object:
129 obj := v
130 outValue := reflect.ValueOf(obj).Elem()
131 typeMeta = outValue.FieldByName("TypeMeta").Interface().(metav1.TypeMeta)
132 objectMeta = outValue.FieldByName("ObjectMeta").Interface().(metav1.ObjectMeta)

Callers 1

InjectMethod · 0.95

Implementers 1

Injectorpkg/application/inject/fuse/injector.g

Calls 15

shouldInjectMethod · 0.95
FromRawToObjectFunction · 0.92
NewApplicationFunction · 0.92
CollectFluidObjectSpecsFunction · 0.92
InjectCacheDirEnabledFunction · 0.92
BuildMutatorFunction · 0.92
OrderedKeysFunction · 0.92
ApplyFluidObjectSpecsFunction · 0.92

Tested by

no test coverage detected