-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct the component spec when get jobservice cr
Signed-off-by: He Weiwei <hweiwei@vmware.com>
- Loading branch information
Showing
17 changed files
with
432 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package harbor_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestHarbor(t *testing.T) { | ||
t.Parallel() | ||
|
||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Harbor Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package harbor_test | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"strings" | ||
|
||
goharborv1alpha2 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha2" | ||
"github.com/goharbor/harbor-operator/controllers" | ||
"github.com/goharbor/harbor-operator/controllers/goharbor/harbor" | ||
"github.com/goharbor/harbor-operator/pkg/config" | ||
"github.com/goharbor/harbor-operator/pkg/factories/application" | ||
"github.com/goharbor/harbor-operator/pkg/factories/logger" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func fileString(filePath string) string { | ||
content, err := ioutil.ReadFile(filePath) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
return strings.TrimSpace(string(content)) | ||
} | ||
|
||
var _ = Describe("Harbor", func() { | ||
var ( | ||
ctx context.Context | ||
decoder runtime.Decoder | ||
r *harbor.Reconciler | ||
|
||
input string | ||
getComponent func(*goharborv1alpha2.Harbor) runtime.Object | ||
output string | ||
) | ||
|
||
BeforeEach(func() { | ||
ctx = logger.Context(zap.LoggerTo(GinkgoWriter, true)) | ||
application.SetName(&ctx, "operator") | ||
application.SetVersion(&ctx, "dev") | ||
|
||
name := controllers.Harbor.String() | ||
|
||
configStore := config.NewConfigWithDefaults() | ||
configStore.Env(name) | ||
|
||
i, err := harbor.New(ctx, name, configStore) | ||
Expect(err).NotTo(HaveOccurred()) | ||
r = i.(*harbor.Reconciler) | ||
|
||
sch := runtime.NewScheme() | ||
_ = goharborv1alpha2.AddToScheme(sch) | ||
|
||
decoder = serializer.NewCodecFactory(sch).UniversalDeserializer() | ||
|
||
input = "" | ||
getComponent = nil | ||
output = "" | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
obj, _, err := decoder.Decode([]byte(input), nil, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
h, ok := obj.(*goharborv1alpha2.Harbor) | ||
Expect(ok).To(BeTrue()) | ||
|
||
bytes, err := yaml.Marshal(getComponent(h)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
output = strings.TrimSpace(string(bytes)) | ||
}) | ||
|
||
Context("GetJobService", func() { | ||
BeforeEach(func() { | ||
getComponent = func(h *goharborv1alpha2.Harbor) runtime.Object { | ||
j, err := r.GetJobService(ctx, h) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
j.SetGroupVersionKind(schema.FromAPIVersionAndKind("goharbor.io/v1alpha2", "JobService")) | ||
|
||
return j | ||
} | ||
}) | ||
|
||
for _, text := range []string{ | ||
"Default", | ||
"Repository and tag suffix not empty", | ||
"Repository not empty", | ||
"Tag suffix not empty", | ||
"Version and repository not empty", | ||
"Version not empty", | ||
} { | ||
text := text | ||
|
||
filename := strings.Join(strings.Split(strings.ToLower(text), " "), "-") | ||
|
||
Context(text, func() { | ||
BeforeEach(func() { | ||
input = fileString("./manifests/jobservice/" + filename + ".yaml") | ||
}) | ||
|
||
It("Should pass", func() { | ||
expected := fileString("./manifests/jobservice/" + filename + "-expected.yaml") | ||
Expect(output).To(BeEquivalentTo(expected)) | ||
}) | ||
}) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
controllers/goharbor/harbor/manifests/jobservice/default-expected.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: JobService | ||
metadata: | ||
annotations: | ||
harbor.goharbor.io/version: "" | ||
creationTimestamp: null | ||
name: example-harbor | ||
namespace: default | ||
spec: | ||
core: | ||
secretRef: example-harbor-core-secret | ||
url: http://example-harbor-core:80 | ||
jobLoggers: | ||
files: | ||
- level: INFO | ||
sweeper: 14h0m0s | ||
loggers: | ||
stdout: | ||
level: INFO | ||
registry: | ||
controllerURL: http://example-harbor-registryctl:80 | ||
credentials: | ||
passwordRef: example-harbor-registry-basicauth | ||
username: harbor_registry_user | ||
url: http://example-harbor-registry | ||
resources: {} | ||
secretRef: example-harbor-jobservice-secret | ||
tokenService: | ||
url: http://example-harbor-core/service/token | ||
workerPool: | ||
redisPool: | ||
database: 2 | ||
host: 127.0.0.1 | ||
port: 3306 | ||
status: | ||
conditions: [] | ||
message: "" | ||
status: "" | ||
|
9 changes: 9 additions & 0 deletions
9
controllers/goharbor/harbor/manifests/jobservice/default.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: Harbor | ||
metadata: | ||
name: example | ||
namespace: default | ||
spec: | ||
redis: | ||
host: 127.0.0.1 | ||
port: 3306 |
39 changes: 39 additions & 0 deletions
39
...rs/goharbor/harbor/manifests/jobservice/repository-and-tag-suffix-not-empty-expected.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: JobService | ||
metadata: | ||
annotations: | ||
harbor.goharbor.io/version: "" | ||
creationTimestamp: null | ||
name: example-harbor | ||
namespace: default | ||
spec: | ||
core: | ||
secretRef: example-harbor-core-secret | ||
url: http://example-harbor-core:80 | ||
image: example.goharbor.io/goharbor/harbor-jobservice:v2.1.2-patch1 | ||
jobLoggers: | ||
files: | ||
- level: INFO | ||
sweeper: 14h0m0s | ||
loggers: | ||
stdout: | ||
level: INFO | ||
registry: | ||
controllerURL: http://example-harbor-registryctl:80 | ||
credentials: | ||
passwordRef: example-harbor-registry-basicauth | ||
username: harbor_registry_user | ||
url: http://example-harbor-registry | ||
resources: {} | ||
secretRef: example-harbor-jobservice-secret | ||
tokenService: | ||
url: http://example-harbor-core/service/token | ||
workerPool: | ||
redisPool: | ||
database: 2 | ||
host: 127.0.0.1 | ||
port: 3306 | ||
status: | ||
conditions: [] | ||
message: "" | ||
status: "" |
12 changes: 12 additions & 0 deletions
12
controllers/goharbor/harbor/manifests/jobservice/repository-and-tag-suffix-not-empty.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: Harbor | ||
metadata: | ||
name: example | ||
namespace: default | ||
spec: | ||
imageSource: | ||
repository: example.goharbor.io/goharbor | ||
tagSuffix: -patch1 | ||
redis: | ||
host: 127.0.0.1 | ||
port: 3306 |
39 changes: 39 additions & 0 deletions
39
controllers/goharbor/harbor/manifests/jobservice/repository-not-empty-expected.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: JobService | ||
metadata: | ||
annotations: | ||
harbor.goharbor.io/version: "" | ||
creationTimestamp: null | ||
name: example-harbor | ||
namespace: default | ||
spec: | ||
core: | ||
secretRef: example-harbor-core-secret | ||
url: http://example-harbor-core:80 | ||
image: example.goharbor.io/goharbor/harbor-jobservice:v2.1.2 | ||
jobLoggers: | ||
files: | ||
- level: INFO | ||
sweeper: 14h0m0s | ||
loggers: | ||
stdout: | ||
level: INFO | ||
registry: | ||
controllerURL: http://example-harbor-registryctl:80 | ||
credentials: | ||
passwordRef: example-harbor-registry-basicauth | ||
username: harbor_registry_user | ||
url: http://example-harbor-registry | ||
resources: {} | ||
secretRef: example-harbor-jobservice-secret | ||
tokenService: | ||
url: http://example-harbor-core/service/token | ||
workerPool: | ||
redisPool: | ||
database: 2 | ||
host: 127.0.0.1 | ||
port: 3306 | ||
status: | ||
conditions: [] | ||
message: "" | ||
status: "" |
11 changes: 11 additions & 0 deletions
11
controllers/goharbor/harbor/manifests/jobservice/repository-not-empty.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: Harbor | ||
metadata: | ||
name: example | ||
namespace: default | ||
spec: | ||
imageSource: | ||
repository: example.goharbor.io/goharbor | ||
redis: | ||
host: 127.0.0.1 | ||
port: 3306 |
39 changes: 39 additions & 0 deletions
39
controllers/goharbor/harbor/manifests/jobservice/tag-suffix-not-empty-expected.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: JobService | ||
metadata: | ||
annotations: | ||
harbor.goharbor.io/version: "" | ||
creationTimestamp: null | ||
name: example-harbor | ||
namespace: default | ||
spec: | ||
core: | ||
secretRef: example-harbor-core-secret | ||
url: http://example-harbor-core:80 | ||
image: goharbor/harbor-jobservice:v2.1.2-patch1 | ||
jobLoggers: | ||
files: | ||
- level: INFO | ||
sweeper: 14h0m0s | ||
loggers: | ||
stdout: | ||
level: INFO | ||
registry: | ||
controllerURL: http://example-harbor-registryctl:80 | ||
credentials: | ||
passwordRef: example-harbor-registry-basicauth | ||
username: harbor_registry_user | ||
url: http://example-harbor-registry | ||
resources: {} | ||
secretRef: example-harbor-jobservice-secret | ||
tokenService: | ||
url: http://example-harbor-core/service/token | ||
workerPool: | ||
redisPool: | ||
database: 2 | ||
host: 127.0.0.1 | ||
port: 3306 | ||
status: | ||
conditions: [] | ||
message: "" | ||
status: "" |
11 changes: 11 additions & 0 deletions
11
controllers/goharbor/harbor/manifests/jobservice/tag-suffix-not-empty.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: Harbor | ||
metadata: | ||
name: example | ||
namespace: default | ||
spec: | ||
imageSource: | ||
tagSuffix: -patch1 | ||
redis: | ||
host: 127.0.0.1 | ||
port: 3306 |
39 changes: 39 additions & 0 deletions
39
...llers/goharbor/harbor/manifests/jobservice/version-and-repository-not-empty-expected.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: goharbor.io/v1alpha2 | ||
kind: JobService | ||
metadata: | ||
annotations: | ||
harbor.goharbor.io/version: 2.1.0 | ||
creationTimestamp: null | ||
name: example-harbor | ||
namespace: default | ||
spec: | ||
core: | ||
secretRef: example-harbor-core-secret | ||
url: http://example-harbor-core:80 | ||
image: example.goharbor.io/goharbor/harbor-jobservice:v2.1.0 | ||
jobLoggers: | ||
files: | ||
- level: INFO | ||
sweeper: 14h0m0s | ||
loggers: | ||
stdout: | ||
level: INFO | ||
registry: | ||
controllerURL: http://example-harbor-registryctl:80 | ||
credentials: | ||
passwordRef: example-harbor-registry-basicauth | ||
username: harbor_registry_user | ||
url: http://example-harbor-registry | ||
resources: {} | ||
secretRef: example-harbor-jobservice-secret | ||
tokenService: | ||
url: http://example-harbor-core/service/token | ||
workerPool: | ||
redisPool: | ||
database: 2 | ||
host: 127.0.0.1 | ||
port: 3306 | ||
status: | ||
conditions: [] | ||
message: "" | ||
status: "" |
Oops, something went wrong.