Skip to content

Commit f58d9e7

Browse files
committed
chore(go): lint errors
1 parent 64d99a1 commit f58d9e7

5 files changed

Lines changed: 32 additions & 26 deletions

File tree

api/v1beta1/snapshot_types.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ type SnapShotSelector struct {
4848
Container string `json:"container"`
4949
}
5050

51+
// SnapShotInputPolicy will(TODO:) add support for Replace, etc ...
5152
type SnapShotInputPolicy string
5253

53-
// TODO: add support for Replace, etc ...
54+
// IfNotPresent only creates a SnapShot if it's not already present
5455
const IfNotPresent SnapShotInputPolicy = "IfNotPresent"
5556

5657
type SnapShotInput struct {
@@ -92,17 +93,24 @@ type SnapShotSpec struct {
9293
type SnapShotStatusStage string
9394

9495
const (
96+
// CriuDumping indicates that we called the kublet api and checkpointing is in progress
9597
CriuDumping SnapShotStatusStage = "CriuDumping"
96-
Fromating SnapShotStatusStage = "Fromating"
97-
Pushing SnapShotStatusStage = "Pushing"
98+
// Fromating indicates that image creation using the checkpoited data is in progress
99+
Fromating SnapShotStatusStage = "Fromating"
100+
// Pushing indicates we're uploading the OCI image to specified container registry
101+
Pushing SnapShotStatusStage = "Pushing"
98102
)
99103

100104
type SnapShotStatusState string
101105

102106
const (
103-
Idle SnapShotStatusState = "Idle"
107+
// Idle indicates the operation has not started
108+
Idle SnapShotStatusState = "Idle"
109+
// Started indicates the operation has started
104110
Started SnapShotStatusState = "Started"
105-
Failed SnapShotStatusState = "Failed"
111+
// Failed indicates the operation has failed
112+
Failed SnapShotStatusState = "Failed"
113+
// Success indicates the operation has completed successfully
106114
Success SnapShotStatusState = "Success"
107115
)
108116

internal/controller/snapshot_controller.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ type CheckPointResp struct {
7171

7272
// Reconcile is part of the main kubernetes reconciliation loop which aims to
7373
// move the current state of the cluster closer to the desired state.
74-
7574
// For more details, check Reconcile and its Result here:
7675
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.21.0/pkg/reconcile
7776
// NOTE: breaking down the Reconcile() function furhter will reduce the readability
@@ -96,9 +95,9 @@ func (r *SnapShotReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
9695
if err != nil {
9796
if requeue {
9897
return ctrl.Result{}, nil
99-
} else {
100-
return ctrl.Result{}, err
10198
}
99+
100+
return ctrl.Result{}, err
102101
}
103102
err = controllerutil.SetControllerReference(snapshot, pod, r.Scheme)
104103
if err != nil {
@@ -228,7 +227,7 @@ func (r *SnapShotReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
228227
}
229228

230229
if snapshot.Status.JobID == "" {
231-
jobId, err := daemonsetInit(
230+
jobID, err := daemonsetInit(
232231
snapshot.Spec.Output.ContainerRegistry,
233232
snapshot.Status.CheckPointNodePath,
234233
snapshot.Status.Node,
@@ -238,7 +237,7 @@ func (r *SnapShotReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
238237
log.Error(err, "unable init daemonset job")
239238
return ctrl.Result{}, err
240239
}
241-
snapshot.Status.JobID = jobId
240+
snapshot.Status.JobID = jobID
242241
if err := r.Status().Update(ctx, snapshot); err != nil {
243242
log.Error(err, "unable to update Snapshot status")
244243
return ctrl.Result{}, err
@@ -309,10 +308,10 @@ func (r *SnapShotReconciler) PodImageUpdate(
309308
}
310309

311310
func daemonsetStausFetch(
312-
jobId string,
311+
jobID string,
313312
node stove8sv1beta1.SnapShotStatusNode,
314313
) (*oci.OciStatus, error) {
315-
ociEndpoint := fmt.Sprintf("http://%s:%v/oci/%s", node.Addr, node.DeamonsetPort, jobId)
314+
ociEndpoint := fmt.Sprintf("http://%s:%v/oci/%s", node.Addr, node.DeamonsetPort, jobID)
316315
req, err := http.NewRequest(http.MethodGet, ociEndpoint, nil)
317316
if err != nil {
318317
return nil, err

internal/daemonset/resources/oci/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type CreateReq struct {
2525
}
2626

2727
type CreateResp struct {
28-
JobId string `json:"job_id"`
28+
JobID string `json:"job_id"`
2929
}
3030

3131
func (rs OciResource) CreateAsync(id uuid.UUID, data *CreateReq) {
@@ -97,7 +97,7 @@ func (rs OciResource) Create(rw http.ResponseWriter, req *http.Request) {
9797
}
9898

9999
resp, err := json.Marshal(CreateResp{
100-
JobId: id.String(),
100+
JobID: id.String(),
101101
})
102102
if err != nil {
103103
slog.Error("Marshaling response json", "err", err.Error())

internal/oci/utils.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
)
2929

3030
const (
31-
ConfigDumpFile = "config.dump"
32-
SpecDumpFile = "spec.dump"
31+
configDumpFile = "config.dump"
32+
specDumpFile = "spec.dump"
3333
)
3434

3535
type ContainerConfig struct {
@@ -135,8 +135,8 @@ func annotationsFromDump(spec *specs.Spec, containerConfig *ContainerConfig) (ma
135135

136136
func dumpInspect(checkpointDump io.Reader) (*specs.Spec, *ContainerConfig, error) {
137137
files := []string{
138-
SpecDumpFile,
139-
ConfigDumpFile,
138+
specDumpFile,
139+
configDumpFile,
140140
}
141141

142142
raw, err := tarFilesRead(files, checkpointDump)
@@ -145,13 +145,13 @@ func dumpInspect(checkpointDump io.Reader) (*specs.Spec, *ContainerConfig, error
145145
}
146146

147147
var spec specs.Spec
148-
err = json.Unmarshal(raw[SpecDumpFile], &spec)
148+
err = json.Unmarshal(raw[specDumpFile], &spec)
149149
if err != nil {
150150
return nil, nil, err
151151
}
152152

153153
var continerConfig ContainerConfig
154-
err = json.Unmarshal(raw[ConfigDumpFile], &continerConfig)
154+
err = json.Unmarshal(raw[configDumpFile], &continerConfig)
155155
if err != nil {
156156
return nil, nil, err
157157
}
@@ -174,9 +174,8 @@ func ReferenceIsValid(refStr string, authSecret *corev1.Secret) (bool, error) {
174174
if err != nil {
175175
if strings.Contains(err.Error(), "not found") || strings.Contains(err.Error(), "404") {
176176
return false, nil
177-
} else {
178-
return false, err
179177
}
178+
return false, err
180179

181180
}
182181

test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"os/exec"
2525
"strings"
2626

27-
. "github.com/onsi/ginkgo/v2" // nolint:revive,staticcheck
27+
"github.com/onsi/ginkgo/v2" // nolint:revive,staticcheck
2828
)
2929

3030
const (
@@ -37,7 +37,7 @@ const (
3737
)
3838

3939
func warnError(err error) {
40-
_, _ = fmt.Fprintf(GinkgoWriter, "warning: %v\n", err)
40+
_, _ = fmt.Fprintf(ginkgo.GinkgoWriter, "warning: %v\n", err)
4141
}
4242

4343
// Run executes the provided command within this context
@@ -46,12 +46,12 @@ func Run(cmd *exec.Cmd) (string, error) {
4646
cmd.Dir = dir
4747

4848
if err := os.Chdir(cmd.Dir); err != nil {
49-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
49+
_, _ = fmt.Fprintf(ginkgo.GinkgoWriter, "chdir dir: %q\n", err)
5050
}
5151

5252
cmd.Env = append(os.Environ(), "GO111MODULE=on")
5353
command := strings.Join(cmd.Args, " ")
54-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
54+
_, _ = fmt.Fprintf(ginkgo.GinkgoWriter, "running: %q\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
5757
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)

0 commit comments

Comments
 (0)