Skip to content

Commit 39e099b

Browse files
authored
Merge pull request #266 from hangscer8/manifest_crd_support_multi_image_repo
Manifest crd support multi image repo
2 parents 0c47a8f + b82d811 commit 39e099b

File tree

8 files changed

+91
-22
lines changed

8 files changed

+91
-22
lines changed

api/apis/manifest/v1alpha1/types.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Spec struct {
4343

4444
type LocalService struct {
4545
// +optional
46-
RegistryRepo string `json:"registryRepo,omitempty" yaml:"registryRepo,omitempty"`
46+
ImageRepo map[ImageRepoType]string `json:"imageRepo" yaml:"imageRepo"`
4747
// +optional
4848
FilesRepo string `json:"filesRepo,omitempty" yaml:"filesRepo,omitempty"`
4949
// +optional
@@ -52,6 +52,21 @@ type LocalService struct {
5252
HostsMap []*HostsMap `json:"hostsMap,omitempty" yaml:"hostsMap,omitempty"`
5353
}
5454

55+
func (localService *LocalService) GetGHCRImageRepo() string {
56+
if localService.ImageRepo == nil {
57+
return ""
58+
}
59+
return localService.ImageRepo[GithubImageRepo]
60+
}
61+
62+
type ImageRepoType string
63+
64+
const KubeImageRepo ImageRepoType = "kubeImageRepo"
65+
const GCRImageRepo ImageRepoType = "gcrImageRepo"
66+
const GithubImageRepo ImageRepoType = "githubImageRepo"
67+
const DockerImageRepo ImageRepoType = "dockerImageRepo"
68+
const QuayImageRepo ImageRepoType = "quayImageRepo"
69+
5570
type HostsMap struct {
5671
// +required
5772
Domain string `json:"domain,omitempty" yaml:"domain,omitempty"`

api/apis/manifest/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/charts/crds/kubean.io_manifests.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ spec:
8686
type: string
8787
type: object
8888
type: array
89-
registryRepo:
90-
type: string
89+
imageRepo:
90+
additionalProperties:
91+
type: string
92+
type: object
9193
yumRepo:
9294
items:
9395
type: string

charts/kubean/crds/kubean.io_manifests.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ spec:
8686
type: string
8787
type: object
8888
type: array
89-
registryRepo:
90-
type: string
89+
imageRepo:
90+
additionalProperties:
91+
type: string
92+
type: object
9193
yumRepo:
9294
items:
9395
type: string

pkg/controllers/infomanifest/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func (c *Controller) UpdateLocalAvailableImage() {
173173
return
174174
}
175175
imageRepo := "ghcr.m.daocloud.io"
176-
if len(global.Spec.LocalService.RegistryRepo) != 0 {
177-
imageRepo = global.Spec.LocalService.RegistryRepo
176+
if len(global.Spec.LocalService.GetGHCRImageRepo()) != 0 {
177+
imageRepo = global.Spec.LocalService.GetGHCRImageRepo() // ghcr.io
178178
}
179179
newImageName := fmt.Sprintf("%s/kubean-io/spray-job:%s", imageRepo, global.Spec.KubeanVersion)
180180
if global.Status.LocalAvailable.KubesprayImage != newImageName {

pkg/controllers/infomanifest/controller_test.go

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,17 @@ func Test_ParseConfigMapToLocalService(t *testing.T) {
168168
},
169169
{
170170
name: "good string data",
171-
arg: &corev1.ConfigMap{Data: map[string]string{"localService": " registryRepo: 'temp-registry.daocloud.io:5000'\n filesRepo: 'http://temp-registry.daocloud.io:9000'\n yumRepo:\n - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n hostsMap:\n - domain: temp-registry.daocloud.io\n address: 'a.b.c.d'"}},
171+
arg: &corev1.ConfigMap{Data: map[string]string{"localService": " imageRepo: \n kubeImageRepo: \"temp-registry.daocloud.io:5000/registry.k8s.io\"\n gcrImageRepo: \"temp-registry.daocloud.io:5000/gcr.io\"\n githubImageRepo: \"a\"\n dockerImageRepo: \"b\"\n quayImageRepo: \"c\"\n filesRepo: 'http://temp-registry.daocloud.io:9000'\n yumRepo:\n - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n hostsMap:\n - domain: temp-registry.daocloud.io\n address: 'a.b.c.d'\n"}},
172172
want: &manifestv1alpha1.LocalService{
173-
RegistryRepo: "temp-registry.daocloud.io:5000",
174-
FilesRepo: "http://temp-registry.daocloud.io:9000",
175-
YumRepo: []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
173+
ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
174+
"kubeImageRepo": "temp-registry.daocloud.io:5000/registry.k8s.io",
175+
"gcrImageRepo": "temp-registry.daocloud.io:5000/gcr.io",
176+
"githubImageRepo": "a",
177+
"dockerImageRepo": "b",
178+
"quayImageRepo": "c",
179+
},
180+
FilesRepo: "http://temp-registry.daocloud.io:9000",
181+
YumRepo: []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
176182
HostsMap: []*manifestv1alpha1.HostsMap{
177183
{Domain: "temp-registry.daocloud.io", Address: "a.b.c.d"},
178184
},
@@ -308,17 +314,23 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
308314
Name: LocalServiceConfigMap,
309315
Namespace: "default",
310316
},
311-
Data: map[string]string{"localService": " registryRepo: 'temp-registry.daocloud.io:5000'\n filesRepo: 'http://temp-registry.daocloud.io:9000'\n yumRepo:\n - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n hostsMap: \n - domain: temp-registry.daocloud.io\n address: 'a.b.c.d'"},
317+
Data: map[string]string{"localService": " imageRepo: \n kubeImageRepo: \"temp-registry.daocloud.io:5000/registry.k8s.io\"\n gcrImageRepo: \"temp-registry.daocloud.io:5000/gcr.io\"\n githubImageRepo: \"a\"\n dockerImageRepo: \"b\"\n quayImageRepo: \"c\"\n filesRepo: 'http://temp-registry.daocloud.io:9000'\n yumRepo:\n - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n hostsMap: \n - domain: temp-registry.daocloud.io\n address: 'a.b.c.d'"},
312318
}
313319
controller.ClientSet.CoreV1().ConfigMaps("default").Create(context.Background(), configMap, metav1.CreateOptions{})
314320
controller.Create(context.Background(), global)
315321
controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Create(context.Background(), global, metav1.CreateOptions{})
316322
controller.UpdateGlobalLocalService()
317323
},
318324
want: manifestv1alpha1.LocalService{
319-
RegistryRepo: "temp-registry.daocloud.io:5000",
320-
FilesRepo: "http://temp-registry.daocloud.io:9000",
321-
YumRepo: []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
325+
ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
326+
"kubeImageRepo": "temp-registry.daocloud.io:5000/registry.k8s.io",
327+
"gcrImageRepo": "temp-registry.daocloud.io:5000/gcr.io",
328+
"githubImageRepo": "a",
329+
"dockerImageRepo": "b",
330+
"quayImageRepo": "c",
331+
},
332+
FilesRepo: "http://temp-registry.daocloud.io:9000",
333+
YumRepo: []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
322334
HostsMap: []*manifestv1alpha1.HostsMap{
323335
{
324336
Domain: "temp-registry.daocloud.io",
@@ -348,17 +360,23 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
348360
Name: LocalServiceConfigMap,
349361
Namespace: "default",
350362
},
351-
Data: map[string]string{"localService": " registryRepo: 'temp-registry.daocloud.io:5000'\n filesRepo: 'http://temp-registry.daocloud.io:9000'\n yumRepo:\n - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n hostsMap: \n - domain: temp-registry.daocloud.io\n address: 'a.b.c.d1'"},
363+
Data: map[string]string{"localService": " imageRepo: \n kubeImageRepo: \"temp-registry.daocloud.io:5000/registry.k8s.io\"\n gcrImageRepo: \"temp-registry.daocloud.io:5000/gcr.io\"\n githubImageRepo: \"a\"\n dockerImageRepo: \"b\"\n quayImageRepo: \"c\"\n filesRepo: 'http://temp-registry.daocloud.io:9000'\n yumRepo:\n - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n hostsMap: \n - domain: temp-registry.daocloud.io\n address: 'a.b.c.d1'"},
352364
}
353365
controller.ClientSet.CoreV1().ConfigMaps("default").Update(context.Background(), configMap, metav1.UpdateOptions{})
354366
controller.Create(context.Background(), global)
355367
controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Create(context.Background(), global, metav1.CreateOptions{})
356368
controller.UpdateGlobalLocalService()
357369
},
358370
want: manifestv1alpha1.LocalService{
359-
RegistryRepo: "temp-registry.daocloud.io:5000",
360-
FilesRepo: "http://temp-registry.daocloud.io:9000",
361-
YumRepo: []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
371+
ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
372+
"kubeImageRepo": "temp-registry.daocloud.io:5000/registry.k8s.io",
373+
"gcrImageRepo": "temp-registry.daocloud.io:5000/gcr.io",
374+
"githubImageRepo": "a",
375+
"dockerImageRepo": "b",
376+
"quayImageRepo": "c",
377+
},
378+
FilesRepo: "http://temp-registry.daocloud.io:9000",
379+
YumRepo: []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
362380
HostsMap: []*manifestv1alpha1.HostsMap{
363381
{
364382
Domain: "temp-registry.daocloud.io",
@@ -429,15 +447,18 @@ func Test_UpdateLocalAvailableImage(t *testing.T) {
429447
Labels: map[string]string{OriginLabel: "v2"},
430448
},
431449
Spec: manifestv1alpha1.Spec{
432-
LocalService: manifestv1alpha1.LocalService{RegistryRepo: "abc.io"},
450+
LocalService: manifestv1alpha1.LocalService{ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
451+
"dockerImageRepo": "abc.io",
452+
"githubImageRepo": "ghcr.io",
453+
}},
433454
KubeanVersion: "123456",
434455
},
435456
}
436457
controller.Update(context.Background(), global)
437458
controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Update(context.Background(), global, metav1.UpdateOptions{})
438459
controller.UpdateLocalAvailableImage()
439460
},
440-
want: "abc.io/kubean-io/spray-job:123456",
461+
want: "ghcr.io/kubean-io/spray-job:123456",
441462
},
442463
}
443464

vendor/kubean.io/api/apis/manifest/v1alpha1/types.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kubean.io/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)