Skip to content

Commit

Permalink
fix: fixed a bug where yurtappset could not be freshed by framework
Browse files Browse the repository at this point in the history
Signed-off-by: LavenderQAQ <1254297317@qq.com>
  • Loading branch information
LavenderQAQ committed Jul 12, 2023
1 parent c50696d commit dca9244
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/controller/platformadmin/platformadmin_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ func (r *ReconcilePlatformAdmin) reconcileConfigmap(ctx context.Context, platfor
needConfigMaps := make(map[string]struct{})
configmaps = platformAdminFramework.ConfigMaps

for _, configmap := range configmaps {
for i, configmap := range configmaps {
configmap.Namespace = platformAdmin.Namespace
configmap.Labels = make(map[string]string)
configmap.Labels[iotv1alpha2.LabelPlatformAdminGenerate] = LabelConfigmap
_, err := controllerutil.CreateOrUpdate(ctx, r.Client, &configmap, func() error {
// Supplement runtime information
configmap.Labels = make(map[string]string)
configmap.Labels[iotv1alpha2.LabelPlatformAdminGenerate] = LabelConfigmap
configmap.Data = platformAdminFramework.ConfigMaps[i].Data
return controllerutil.SetOwnerReference(platformAdmin, &configmap, (r.Scheme()))
})
if err != nil {
Expand Down Expand Up @@ -393,7 +393,6 @@ func (r *ReconcilePlatformAdmin) reconcileComponent(ctx context.Context, platfor
platformAdminStatus.UnreadyComponentNum = int32(len(desireComponents)) - readyComponent
}()

NextC:
for _, desireComponent := range desireComponents {
readyService := false
readyDeployment := false
Expand All @@ -404,7 +403,13 @@ NextC:
}
readyService = true

yas := &appsv1alpha1.YurtAppSet{}
yas := &appsv1alpha1.YurtAppSet{
ObjectMeta: metav1.ObjectMeta{
Name: desireComponent.Name,
Namespace: platformAdmin.Namespace,
},
}

err := r.Get(
ctx,
types.NamespacedName{
Expand All @@ -422,14 +427,16 @@ NextC:
} else {
oldYas := yas.DeepCopy()

// Refresh the YurtAppSet according to the user-defined configuration
yas.Spec.WorkloadTemplate.DeploymentTemplate.Spec = *desireComponent.Deployment

if _, ok := yas.Status.PoolReplicas[platformAdmin.Spec.PoolName]; ok {
if yas.Status.ReadyReplicas == yas.Status.Replicas {
readyDeployment = true
if readyDeployment && readyService {
readyComponent++
}
}
continue NextC
}
pool := appsv1alpha1.Pool{
Name: platformAdmin.Spec.PoolName,
Expand Down Expand Up @@ -500,19 +507,18 @@ func (r *ReconcilePlatformAdmin) handleService(ctx context.Context, platformAdmi
Namespace: platformAdmin.Namespace,
},
}
service.Labels[iotv1alpha2.LabelPlatformAdminGenerate] = LabelService
service.Annotations[AnnotationServiceTopologyKey] = AnnotationServiceTopologyValueNodePool

_, err := controllerutil.CreateOrUpdate(
ctx,
r.Client,
service,
func() error {
service.Labels[iotv1alpha2.LabelPlatformAdminGenerate] = LabelService
service.Annotations[AnnotationServiceTopologyKey] = AnnotationServiceTopologyValueNodePool
service.Spec = *component.Service
return controllerutil.SetOwnerReference(platformAdmin, service, r.Scheme())
},
)

if err != nil {
return nil, err
}
Expand Down

0 comments on commit dca9244

Please sign in to comment.