Skip to content

Commit

Permalink
improve status reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Batschelet <[email protected]>
  • Loading branch information
hexfusion committed Apr 13, 2024
1 parent 4baf618 commit 8693696
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
34 changes: 29 additions & 5 deletions pkg/daemon/pinned_image_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (p *PinnedImageSetManager) syncMachineConfigPool(ctx context.Context, pool
if err != nil {
return fmt.Errorf("failed to get PinnedImageSet %q: %w", ref.Name, err)
}
klog.Infof("Reconciling pinned image set: %s", ref.Name)
klog.Infof("Reconciling pinned image set: %s: generation: %d", ref.Name, imageSet.GetGeneration())

// verify storage per image set
if err := p.checkNodeAllocatableStorage(ctx, imageSet); err != nil {
Expand Down Expand Up @@ -490,7 +490,7 @@ func (p *PinnedImageSetManager) updateStatusProgressingComplete(pools []*mcfgv1.
Reason: "AsExpected",
Message: message,
},
nil, // for now we don't have a child status
nil,
metav1.ConditionFalse,
metav1.ConditionUnknown,
node,
Expand All @@ -510,7 +510,7 @@ func (p *PinnedImageSetManager) updateStatusProgressingComplete(pools []*mcfgv1.
Reason: "AsExpected",
Message: "All is good",
},
nil, // for now we don't have a child status
nil,
metav1.ConditionFalse,
metav1.ConditionUnknown,
node,
Expand All @@ -537,13 +537,38 @@ func (p *PinnedImageSetManager) updateStatusError(pools []*mcfgv1.MachineConfigP
return
}

err = upgrademonitor.UpdateMachineConfigNodeStatus(
&upgrademonitor.Condition{
State: mcfgv1alpha1.MachineConfigNodePinnedImageSetsProgressing,
Reason: "ImagePrefetch",
Message: fmt.Sprintf("node is prefetching images: %s", node.Name),
},
nil,
metav1.ConditionTrue,
metav1.ConditionUnknown,
node,
p.mcfgClient,
applyCfg,
imageSets,
p.featureGatesAccessor,
)
if err != nil {
klog.Errorf("Failed to updated machine config node: %v", err)
}

applyCfg, imageSets, err = getImageSetApplyConfigs(p.imageSetLister, pools, statusErr)
if err != nil {
klog.Errorf("Failed to get image set apply configs: %v", err)
return
}

err = upgrademonitor.UpdateMachineConfigNodeStatus(
&upgrademonitor.Condition{
State: mcfgv1alpha1.MachineConfigNodePinnedImageSetsDegraded,
Reason: "PrefetchFailed",
Message: "Error: " + statusErr.Error(),
},
nil, // for now we don't have a child status
nil,
metav1.ConditionTrue,
metav1.ConditionUnknown,
node,
Expand Down Expand Up @@ -637,7 +662,6 @@ func scheduleWork(ctx context.Context, prefetchCh chan prefetch, registryAuth *r
if updateIncrement == 0 {
updateIncrement = 1 // Ensure there's at least one update if the image count is less than 4
}
klog.Infof("scheduling prefetch work for %d images", len(prefetchImages))
processedImages := 0
for _, imageRef := range prefetchImages {
select {
Expand Down
6 changes: 2 additions & 4 deletions pkg/daemon/pinned_image_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestPrefetchImageSets(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

fakeMCOClient := fakemco.NewSimpleClientset(tt.machineConfigPools...)
Expand Down Expand Up @@ -301,9 +301,6 @@ func TestPrefetchImageSets(t *testing.T) {
prefetchCh: make(chan prefetch, defaultPrefetchWorkers*2),
}

// ctx, cancel = context.WithTimeout(ctx, 1*time.Second)
// defer cancel()

imageSets := make([]*mcfgv1alpha1.PinnedImageSet, len(tt.imageSets))
for i, obj := range tt.imageSets {
imageSet, ok := obj.(*mcfgv1alpha1.PinnedImageSet)
Expand All @@ -322,6 +319,7 @@ func TestPrefetchImageSets(t *testing.T) {
err = p.prefetchImageSets(ctx, imageSets...)
require.NoError(err)
wg.Wait()
time.Sleep(3 * time.Second)
require.Equal(tt.wantPulledImages, runtime.imagesPulled())
})
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/upgrademonitor/upgrade_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/utils/ptr"

v1 "github.com/openshift/api/config/v1"
mcfgalphav1 "github.com/openshift/api/machineconfiguration/v1alpha1"
Expand Down Expand Up @@ -242,9 +243,19 @@ func generateAndApplyMachineConfigNodes(

if imageSetApplyConfig != nil {
statusApplyConfig = statusApplyConfig.WithPinnedImageSets(imageSetApplyConfig...)
} else {
// use the existing image sets
for _, imageSet := range newMCNode.Status.PinnedImageSets {
statusApplyConfig = statusApplyConfig.WithPinnedImageSets(&machineconfigurationalphav1.MachineConfigNodeStatusPinnedImageSetApplyConfiguration{
DesiredGeneration: ptr.To(imageSet.DesiredGeneration),
CurrentGeneration: ptr.To(imageSet.CurrentGeneration),
Name: ptr.To(imageSet.Name),
LastFailedGeneration: ptr.To(imageSet.LastFailedGeneration),
LastFailedGenerationErrors: imageSet.LastFailedGenerationErrors,
})
}
}

// TODO: update client-go to bring in updates
mcnodeApplyConfig := machineconfigurationalphav1.MachineConfigNode(newMCNode.Name).WithStatus(statusApplyConfig)
_, err := mcfgClient.MachineconfigurationV1alpha1().MachineConfigNodes().ApplyStatus(context.TODO(), mcnodeApplyConfig, metav1.ApplyOptions{FieldManager: "machine-config-operator", Force: true})
if err != nil {
Expand Down

0 comments on commit 8693696

Please sign in to comment.