// Schedule decides which cluster the apps is scheduled to
Schedule decides which cluster the apps is scheduled to
// Schedule decides which cluster the apps is scheduled to
func (o *OCMEngine) Schedule(ctx context.Context, apps []*EnvBindApp) error {
	for i := range apps {
		app := apps[i]
		app.ManifestWork = make(map[string]*unstructured.Unstructured, len(app.assembledManifests))
		clusterName := o.clusterDecisions[app.envConfig.Name]
		for componentName, manifest := range app.assembledManifests {
			manifestWork := new(ocmworkv1.ManifestWork)
			manifestWorkName := fmt.Sprintf("%s-%s-%s", app.envConfig.Name, o.appName, componentName)
			manifestWork.SetName(manifestWorkName)
			manifestWork.SetNamespace(clusterName)
			workloads := make([]ocmworkv1.Manifest, len(manifest))
			for j, workload := range manifest {
				workloads[j] = ocmworkv1.Manifest{
					RawExtension: util.Object2RawExtension(workload),
				}
			}
			manifestWork.Spec.Workload.Manifests = workloads
			obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(manifestWork)
			if err != nil {
				return err
			}
			unstructuredManifestWork := &unstructured.Unstructured{
				Object: obj,
			}
			unstructuredManifestWork.SetGroupVersionKind(ocmworkv1.GroupVersion.WithKind(reflect.TypeOf(ocmworkv1.ManifestWork{}).Name()))
			app.ManifestWork[componentName] = unstructuredManifestWork
		}
	}
	return nil
}
func ( o * OCMEngine ) Schedule ( ctx context . Context , apps [ ] * EnvBindApp ) error { for i := range apps { app := apps [ i ] app . ManifestWork = make ( map [ string ] * unstructured . Unstructured , len ( app . assembledManifests ) ) clusterName := o . clusterDecisions [ app . envConfig . Name ] for componentName , manifest := range app . assembledManifests { manifestWork := new ( ocmworkv1 . ManifestWork ) manifestWorkName := fmt . Sprintf ( " " , app . envConfig . Name , o . appName , componentName ) manifestWork . SetName ( manifestWorkName ) manifestWork . SetNamespace ( clusterName ) workloads := make ( [ ] ocmworkv1 . Manifest , len ( manifest ) ) for j , workload := range manifest { workloads [ j ] = ocmworkv1 . Manifest { RawExtension : util . Object2RawExtension ( workload ) , } } manifestWork . Spec . Workload . Manifests = workloads obj , err := runtime . DefaultUnstructuredConverter . ToUnstructured ( manifestWork ) if err != nil { return err } unstructuredManifestWork := & unstructured . Unstructured { Object : obj , } unstructuredManifestWork . SetGroupVersionKind ( ocmworkv1 . GroupVersion . WithKind ( reflect . TypeOf ( ocmworkv1 . ManifestWork { } ) . Name ( ) ) ) app . ManifestWork [ componentName ] = unstructuredManifestWork } } return nil }
Schedule decides which cluster the apps is scheduled to
Schedule decides which cluster the apps is scheduled to