Repository: kubernetes-sigs/kube-scheduler-simulator
Pull request #365 (2024-08-21 06:30:17)

Rename `ImportClusterResourceService` to `OneshotClusterResourceImporter`
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide/first-contribution.md#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

#### What type of PR is this?

/area simulator
/kind cleanup

<!--
Add related area tag(s):
/area web

/area scenario

Add one of the following kinds:
/kind bug

/kind documentation
/kind feature

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:

If we add the syncing service (#327), it has two features to import resources of a real cluster, one-shot importing and continuous syncing.
So the current naming of `ImportClusterResouceService` would be confusing.

This PR renames `ImportClusterResourceService` to `OneshotClusterResourceImporter`. This will avoid the confusion.

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Part of #327 

#### Special notes for your reviewer:

We should also rename `mock_clusterresourceimporter`, but this is generated by gomock so we need to replace golang/mock with uber-go/mock (#363). This PR once leaves it.

/label tide/merge-method-squash


k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/365#" title="Author self-approved">saza-ku</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign [sanposhiho](https://github.com/sanposhiho) for approval. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkube-scheduler-simulator).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-simulator/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["sanposhiho"]} -->
k8s-ci-robot: Hi @saza-ku. Thanks for your PR.

I'm waiting for a [kubernetes-sigs](https://github.com/orgs/kubernetes-sigs/people) member to verify that this patch is reasonable to test. If it is, they should reply with `/ok-to-test` on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should [join the org](https://git.k8s.io/community/community-membership.md#member) to skip this step.

Once the patch is verified, the new status will be reflected by the `ok-to-test` label.

I understand the commands that are listed [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkube-scheduler-simulator).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
</details>

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/365#pullrequestreview-2249958651" title="Approved">ordovicia</a>*, *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/365#" title="Author self-approved">saza-ku</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign [sanposhiho](https://github.com/sanposhiho) for approval. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkube-scheduler-simulator).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-simulator/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["sanposhiho"]} -->
sanposhiho: /ok-to-test
k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/365#pullrequestreview-2249958651" title="Approved">ordovicia</a>*, *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/365#pullrequestreview-2251292914" title="Approved">sanposhiho</a>*, *<a href="https://github.com/kubernetes-sigs/kube-scheduler-simulator/pull/365#" title="Author self-approved">saza-ku</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkube-scheduler-simulator).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-simulator/blob/master/OWNERS)~~ [sanposhiho]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/simulator/cmd/scheduler/Dockerfile b/simulator/cmd/scheduler/Dockerfile
index dd7af284..d80471e8 100644
--- a/simulator/cmd/scheduler/Dockerfile
+++ b/simulator/cmd/scheduler/Dockerfile
@@ -7,13 +7,17 @@ ENV GOARCH=${TARGETARCH}
 ENV CGO_ENABLED=0
 ENV GO111MODULE=on
 
+RUN go env -w GOCACHE=/go-cache
+RUN go env -w GOMODCACHE=/gomod-cache
+
 WORKDIR /go/src/simulator
 
 COPY go.mod go.sum ./
-RUN go mod download
+RUN --mount=type=cache,target=/gomod-cache go mod download
 
 COPY . .
-RUN go build -v -o ./bin/scheduler ./cmd/scheduler/scheduler.go
+RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
+    go build -v -o ./bin/scheduler ./cmd/scheduler/scheduler.go
 
 FROM alpine:3.14.0
 
diff --git a/simulator/cmd/simulator/Dockerfile b/simulator/cmd/simulator/Dockerfile
index e85d9ab9..2261fba4 100644
--- a/simulator/cmd/simulator/Dockerfile
+++ b/simulator/cmd/simulator/Dockerfile
@@ -8,13 +8,17 @@ ENV GOARCH=${TARGETARCH}
 ENV CGO_ENABLED=0
 ENV GO111MODULE=on
 
+RUN go env -w GOCACHE=/go-cache
+RUN go env -w GOMODCACHE=/gomod-cache
+
 WORKDIR /go/src/simulator
 
 COPY go.mod go.sum ./
-RUN go mod download
+RUN --mount=type=cache,target=/gomod-cache go mod download
 
 COPY . .
-RUN go build -v -o ./bin/simulator ./cmd/simulator/simulator.go
+RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
+    go build -v -o ./bin/simulator ./cmd/simulator/simulator.go
 
 FROM alpine:3.14.0
 
diff --git a/simulator/cmd/simulator/simulator.go b/simulator/cmd/simulator/simulator.go
index 31d7af78..77fde939 100644
--- a/simulator/cmd/simulator/simulator.go
+++ b/simulator/cmd/simulator/simulator.go
@@ -88,7 +88,7 @@ func startSimulator() error {
 	if cfg.ExternalImportEnabled {
 		ctx := context.Background()
 		// This must be called after `StartScheduler`
-		if err := dic.ImportClusterResourceService().ImportClusterResources(ctx); err != nil {
+		if err := dic.OneshotClusterResourceImporter().ImportClusterResources(ctx); err != nil {
 			return xerrors.Errorf("import from the target cluster: %w", err)
 		}
 	}
diff --git a/simulator/clusterresourceimporter/importer.go b/simulator/oneshotimporter/importer.go
similarity index 98%
rename from simulator/clusterresourceimporter/importer.go
rename to simulator/oneshotimporter/importer.go
index c62a9afb..f939e960 100644
--- a/simulator/clusterresourceimporter/importer.go
+++ b/simulator/oneshotimporter/importer.go
@@ -1,4 +1,4 @@
-package clusterresourceimporter
+package oneshotimporter
 
 //go:generate mockgen -destination=./mock_$GOPACKAGE/replicate.go . ReplicateService
 
diff --git a/simulator/clusterresourceimporter/mock_clusterresourceimporter/replicate.go b/simulator/oneshotimporter/mock_clusterresourceimporter/replicate.go
similarity index 100%
rename from simulator/clusterresourceimporter/mock_clusterresourceimporter/replicate.go
rename to simulator/oneshotimporter/mock_clusterresourceimporter/replicate.go
diff --git a/simulator/server/di/di.go b/simulator/server/di/di.go
index 35812da5..543dc86e 100644
--- a/simulator/server/di/di.go
+++ b/simulator/server/di/di.go
@@ -10,7 +10,7 @@ import (
 	restclient "k8s.io/client-go/rest"
 	configv1 "k8s.io/kube-scheduler/config/v1"
 
-	"sigs.k8s.io/kube-scheduler-simulator/simulator/clusterresourceimporter"
+	"sigs.k8s.io/kube-scheduler-simulator/simulator/oneshotimporter"
 	"sigs.k8s.io/kube-scheduler-simulator/simulator/reset"
 	"sigs.k8s.io/kube-scheduler-simulator/simulator/resourcewatcher"
 	"sigs.k8s.io/kube-scheduler-simulator/simulator/scheduler"
@@ -19,11 +19,11 @@ import (
 
 // Container saves and provides dependencies.
 type Container struct {
-	schedulerService             SchedulerService
-	snapshotService              SnapshotService
-	resetService                 ResetService
-	importClusterResourceService ImportClusterResourceService
-	resourceWatcherService       ResourceWatcherService
+	schedulerService               SchedulerService
+	snapshotService                SnapshotService
+	resetService                   ResetService
+	oneshotClusterResourceImporter OneShotClusterResourceImporter
+	resourceWatcherService         ResourceWatcherService
 }
 
 // NewDIContainer initializes Container.
@@ -52,7 +52,7 @@ func NewDIContainer(
 	c.snapshotService = snapshotSvc
 	if externalImportEnabled {
 		extSnapshotSvc := snapshot.NewService(externalClient, c.schedulerService)
-		c.importClusterResourceService = clusterresourceimporter.NewService(snapshotSvc, extSnapshotSvc)
+		c.oneshotClusterResourceImporter = oneshotimporter.NewService(snapshotSvc, extSnapshotSvc)
 	}
 	c.resourceWatcherService = resourcewatcher.NewService(client)
 
@@ -74,10 +74,10 @@ func (c *Container) ResetService() ResetService {
 	return c.resetService
 }
 
-// ImportClusterResourceService returns ImportClusterResourceService.
+// OneshotClusterResourceImporter returns OneshotClusterResourceImporter.
 // Note: this service will return nil when `externalImportEnabled` is false.
-func (c *Container) ImportClusterResourceService() ImportClusterResourceService {
-	return c.importClusterResourceService
+func (c *Container) OneshotClusterResourceImporter() OneShotClusterResourceImporter {
+	return c.oneshotClusterResourceImporter
 }
 
 // ResourceWatcherService returns ResourceWatcherService.
diff --git a/simulator/server/di/interface.go b/simulator/server/di/interface.go
index da461b7f..43cca59d 100644
--- a/simulator/server/di/interface.go
+++ b/simulator/server/di/interface.go
@@ -33,8 +33,8 @@ type ResetService interface {
 	Reset(ctx context.Context) error
 }
 
-// ImportClusterResourceService represents a service to import resources from an target cluster.
-type ImportClusterResourceService interface {
+// OneShotClusterResourceImporter represents a service to import resources from an target cluster when starting the simulator.
+type OneShotClusterResourceImporter interface {
 	ImportClusterResources(ctx context.Context) error
 }
 


Test patch:
diff --git a/simulator/clusterresourceimporter/importer_test.go b/simulator/oneshotimporter/importer_test.go
similarity index 95%
rename from simulator/clusterresourceimporter/importer_test.go
rename to simulator/oneshotimporter/importer_test.go
index 2b636354..b3836020 100644
--- a/simulator/clusterresourceimporter/importer_test.go
+++ b/simulator/oneshotimporter/importer_test.go
@@ -1,4 +1,4 @@
-package clusterresourceimporter
+package oneshotimporter
 
 import (
 	"context"
@@ -7,7 +7,7 @@ import (
 	"github.com/golang/mock/gomock"
 	"golang.org/x/xerrors"
 
-	m "sigs.k8s.io/kube-scheduler-simulator/simulator/clusterresourceimporter/mock_clusterresourceimporter"
+	m "sigs.k8s.io/kube-scheduler-simulator/simulator/oneshotimporter/mock_clusterresourceimporter"
 	"sigs.k8s.io/kube-scheduler-simulator/simulator/snapshot"
 )