Skip to content

Commit cef861a

Browse files
committed
feat: add certs.d volume
Signed-off-by: coderth <[email protected]>
1 parent c87b5c7 commit cef861a

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

internal/controller/runtime/docker_compatible.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (d *dockerCompatibleRuntime) Pull(ctx context.Context, image string, auth *
4747
}
4848

4949
func (d *dockerCompatibleRuntime) Push(ctx context.Context, image string, auth *Auth) error {
50-
return d.withLoginContextCommands(ctx, auth, []string{"push", image}, nil)
50+
return d.withLoginContextCommands(ctx, auth, append([]string{"push", image}), nil)
5151
}
5252

5353
func (d *dockerCompatibleRuntime) withLoginContextCommands(ctx context.Context, auth *Auth, args []string, stdin io.Reader) error {

internal/controller/snapshotpodtask_controller.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ import (
2626
"github.com/containers/image/v5/docker/reference"
2727
"github.com/samber/lo"
2828
corev1 "k8s.io/api/core/v1"
29+
"k8s.io/apimachinery/pkg/api/errors"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30-
3131
"k8s.io/apimachinery/pkg/runtime"
3232
ctrl "sigs.k8s.io/controller-runtime"
3333
"sigs.k8s.io/controller-runtime/pkg/client"
3434
"sigs.k8s.io/controller-runtime/pkg/log"
3535

36-
criruntime "github.com/baizeai/kube-snapshot/internal/controller/runtime"
37-
3836
snapshotpodv1alpha1 "github.com/baizeai/kube-snapshot/api/v1alpha1"
37+
criruntime "github.com/baizeai/kube-snapshot/internal/controller/runtime"
3938
)
4039

4140
const (
@@ -148,6 +147,9 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
148147
spt := snapshotpodv1alpha1.SnapshotPodTask{}
149148
err := r.Client.Get(ctx, req.NamespacedName, &spt)
150149
if err != nil {
150+
if errors.IsNotFound(err) {
151+
return ctrl.Result{}, nil
152+
}
151153
return ctrl.Result{}, err
152154
}
153155
if spt.Spec.NodeName != r.NodeName {
@@ -196,6 +198,10 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
196198
logger.Error(err, "run reconcile task error", "type", rec.typ, "namespace", spt.Namespace, "name", spt.Name)
197199
spt.Status.Conditions[i].Status = metav1.ConditionFalse
198200
spt.Status.Conditions[i].Message = err.Error()
201+
// Update status immediately after error
202+
if updateErr := r.Status().Update(ctx, &spt); updateErr != nil {
203+
return ctrl.Result{}, updateErr
204+
}
199205
break
200206
} else {
201207
spt.Status.Conditions[i].Status = metav1.ConditionTrue
@@ -205,7 +211,13 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
205211
// update LastTransitionTime if condition changed.
206212
spt.Status.Conditions[i].LastTransitionTime = metav1.Now()
207213
}
214+
// Update status after each successful step
215+
if updateErr := r.Status().Update(ctx, &spt); updateErr != nil {
216+
return ctrl.Result{}, updateErr
217+
}
208218
}
219+
220+
// Update phase based on conditions
209221
switch {
210222
case lo.EveryBy(spt.Status.Conditions, func(item metav1.Condition) bool {
211223
return item.Status == metav1.ConditionTrue
@@ -220,9 +232,11 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
220232
spt.Status.Phase = snapshotpodv1alpha1.SnapshotPodTaskPhaseCreated
221233
}
222234

235+
// Final status update for phase change
223236
if err := r.Status().Update(ctx, &spt); err != nil {
224237
return ctrl.Result{}, err
225238
}
239+
226240
switch spt.Status.Phase {
227241
case snapshotpodv1alpha1.SnapshotPodTaskPhaseFailed, snapshotpodv1alpha1.SnapshotPodTaskPhaseCompleted:
228242
return ctrl.Result{}, nil

manifests/snapshot-pod/templates/daemonset.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ spec:
2929
hostPath:
3030
path: /var/run/
3131
type: ''
32+
- name: host-certs
33+
hostPath:
34+
path: /etc/containerd/certs.d
35+
type: Directory
3236
{{ if .Values.systemWideDockerSecret }}
3337
- name: docker-registry-secret
3438
secret:
@@ -60,6 +64,8 @@ spec:
6064
volumeMounts:
6165
- name: host-run
6266
mountPath: /var/run/
67+
- name: host-certs
68+
mountPath: /etc/containerd/certs.d
6369
{{ if .Values.systemWideDockerSecret }}
6470
- name: docker-registry-secret
6571
mountPath: /root/.docker/system-wide/config.json

0 commit comments

Comments
 (0)