func()

in operator/pkg/operator/injector/injector.go [387:440]


func (s *SidecarInjectField) OverlayOptional(swAgentL []v1alpha1.SwAgent, annotation *map[string]string) {
	sourceOptionalPath := strings.Join([]string{s.SidecarVolumeMount.MountPath, "optional-plugins/"}, "/")
	sourceOptionalReporterPath := strings.Join([]string{s.SidecarVolumeMount.MountPath, "optional-reporter-plugins/"}, "/")
	sourceBootstrapPath := strings.Join([]string{s.SidecarVolumeMount.MountPath, "bootstrap-plugins/"}, "/")
	targetPath := strings.Join([]string{s.SidecarVolumeMount.MountPath, "plugins/"}, "/")

	command := ""
	optionalPlugin := ""
	optionalReporterPlugins := ""
	bootstrapPlugins := ""

	// chose the last matched SwAgent
	if len(swAgentL) > 0 {
		swAgent := swAgentL[len(swAgentL)-1]
		log.Info(fmt.Sprintf("agent %s loaded.", swAgent.Name))
		if len(swAgent.Spec.OptionalPlugins) > 0 {
			optionalPlugin = strings.Join(swAgent.Spec.OptionalPlugins, "|")
		}
		if len(swAgent.Spec.OptionalReporterPlugins) > 0 {
			optionalReporterPlugins = strings.Join(swAgent.Spec.OptionalReporterPlugins, "|")
		}
		if len(swAgent.Spec.BootstrapPlugins) > 0 {
			bootstrapPlugins = strings.Join(swAgent.Spec.BootstrapPlugins, "|")
		}
	}

	for k, v := range *annotation {
		if strings.EqualFold(k, optionsAnnotation) {
			optionalPlugin = v
		} else if strings.EqualFold(k, optionsReporterAnnotation) {
			optionalReporterPlugins = v
		} else if strings.EqualFold(k, bootstrapAnnotation) {
			bootstrapPlugins = v
		}
		if command != "" {
			s.Initcontainer.Args[1] = strings.Join([]string{s.Initcontainer.Args[1], command}, " && ")
		}
	}

	if len(optionalPlugin) > 0 {
		command = "cd " + sourceOptionalPath + " && ls | grep -E \"" + optionalPlugin + "\"  | xargs -i cp {} " + targetPath
		s.Initcontainer.Args[1] = strings.Join([]string{s.Initcontainer.Args[1], command}, " && ")
	}

	if len(optionalReporterPlugins) > 0 {
		command = "cd " + sourceOptionalReporterPath + " && ls | grep -E \"" + optionalReporterPlugins + "\"  | xargs -i cp {} " + targetPath
		s.Initcontainer.Args[1] = strings.Join([]string{s.Initcontainer.Args[1], command}, " && ")
	}

	if len(bootstrapPlugins) > 0 {
		command = "cd " + sourceBootstrapPath + " && ls | grep -E \"" + bootstrapPlugins + "\"  | xargs -i cp {} " + targetPath
		s.Initcontainer.Args[1] = strings.Join([]string{s.Initcontainer.Args[1], command}, " && ")
	}
}