mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
fix: test kk push image to harbor. (#2457)
Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
parent
b79482aa05
commit
3e56b095de
|
|
@ -2,6 +2,9 @@
|
||||||
- localhost
|
- localhost
|
||||||
tags: ["always"]
|
tags: ["always"]
|
||||||
roles:
|
roles:
|
||||||
- init/init-artifact
|
- role: init/init-artifact
|
||||||
- init/init-cert
|
tags: ["always"]
|
||||||
- install/image-registry
|
- role: init/init-cert
|
||||||
|
tags: ["always"]
|
||||||
|
- role: install/image-registry
|
||||||
|
tags: ["always"]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
image_registry:
|
image_registry:
|
||||||
# ha_vip: 192.168.122.59
|
# ha_vip: 192.168.122.59
|
||||||
namespace_override: ""
|
namespace_override: ""
|
||||||
|
# which store images data which will push to registry.
|
||||||
|
images_dir: /tmp/kubekey/images/
|
||||||
auth:
|
auth:
|
||||||
registry: |
|
registry: |
|
||||||
{{- if and .image_registry.ha_vip (ne .image_registry.ha_vip "") }}
|
{{- if and .image_registry.ha_vip (ne .image_registry.ha_vip "") }}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@
|
||||||
copy:
|
copy:
|
||||||
src: |
|
src: |
|
||||||
{{ .work_dir }}/kubekey/images/
|
{{ .work_dir }}/kubekey/images/
|
||||||
dest: /tmp/kubekey/images/
|
dest: |
|
||||||
|
{{ .image_registry.images_dir }}
|
||||||
|
|
||||||
- name: Create harbor project for each image
|
- name: Create harbor project for each image
|
||||||
tags: ["only_image"]
|
tags: ["only_image"]
|
||||||
command: |
|
command: |
|
||||||
{{- if .image_registry.namespace_override | eq "" }}
|
{{- if .image_registry.namespace_override | eq "" }}
|
||||||
for dir in /tmp/kubekey/images/*; do
|
for dir in {{ .image_registry.images_dir }}*; do
|
||||||
if [ ! -d "$dir" ]; then
|
if [ ! -d "$dir" ]; then
|
||||||
# only deal with directories
|
# only deal with directories
|
||||||
continue
|
continue
|
||||||
|
|
@ -18,24 +19,24 @@
|
||||||
|
|
||||||
project=${dir##*/}
|
project=${dir##*/}
|
||||||
|
|
||||||
if [ "$project" == "blobs" ]; then
|
if [[ "$project" == "blobs" ]]; then
|
||||||
# skip blobs dir
|
# skip blobs dir
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if project is not exist, create if
|
# if project is not exist, create it
|
||||||
http_code=$(curl -Iks -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" 'https://localhost/api/v2.0/projects?project_name=${project}' | grep HTTP | awk '{print $2}')
|
resp=$(curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X GET "https://{{ .image_registry.auth.registry }}/api/v2.0/projects/${project}")
|
||||||
if [ $http_code == 404 ]; then
|
if echo "$resp" | grep -q '"code":"NOT_FOUND"'; then
|
||||||
# create project
|
# create project
|
||||||
curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X POST -H "Content-Type: application/json" "https://localhost/api/v2.0/projects" -d "{ \"project_name\": \"${project}\", \"public\": true}"
|
curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X POST -H "Content-Type: application/json" "https://{{ .image_registry.auth.registry }}/api/v2.0/projects" -d "{ \"project_name\": \"${project}\", \"public\": true}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
{{- else }}
|
{{- else }}
|
||||||
# if project is not exist, create if
|
# if project is not exist, create it
|
||||||
http_code=$(curl -Iks -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" 'https://localhost/api/v2.0/projects?project_name={{ .image_registry.namespace_override }}' | grep HTTP | awk '{print $2}')
|
resp=$(curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X GET "https://{{ .image_registry.auth.registry }}/api/v2.0/projects/{{ .image_registry.namespace_override }}")
|
||||||
if [ $http_code == 404 ]; then
|
if echo "$resp" | grep -q '"code":"NOT_FOUND"'; then
|
||||||
# create project
|
# create project
|
||||||
curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X POST -H "Content-Type: application/json" "https://localhost/api/v2.0/projects" -d "{ \"project_name\": \"{{ .image_registry.namespace_override }}\", \"public\": true}"
|
curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X POST -H "Content-Type: application/json" "https://{{ .image_registry.auth.registry }}/api/v2.0/projects" -d "{ \"project_name\": \"{{ .image_registry.namespace_override }}\", \"public\": true}"
|
||||||
fi
|
fi
|
||||||
{{- end }}
|
{{- end }}
|
||||||
when: .image_registry.type | eq "harbor"
|
when: .image_registry.type | eq "harbor"
|
||||||
|
|
@ -44,7 +45,8 @@
|
||||||
tags: ["only_image"]
|
tags: ["only_image"]
|
||||||
image:
|
image:
|
||||||
push:
|
push:
|
||||||
images_dir: /tmp/kubekey/images/
|
images_dir: |
|
||||||
|
{{ .image_registry.images_dir }}
|
||||||
registry: |
|
registry: |
|
||||||
{{ .image_registry.auth.registry }}
|
{{ .image_registry.auth.registry }}
|
||||||
namespace_override: |
|
namespace_override: |
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ func NewControllerManagerServerOptions() *ControllerManagerServerOptions {
|
||||||
func (o *ControllerManagerServerOptions) Flags() cliflag.NamedFlagSets {
|
func (o *ControllerManagerServerOptions) Flags() cliflag.NamedFlagSets {
|
||||||
fss := cliflag.NamedFlagSets{}
|
fss := cliflag.NamedFlagSets{}
|
||||||
gfs := fss.FlagSet("generic")
|
gfs := fss.FlagSet("generic")
|
||||||
gfs.StringVar(&o.WorkDir, "work-dir", o.WorkDir, "the base Dir for kubekey. Default current dir. ")
|
gfs.StringVar(&o.WorkDir, "workdir", o.WorkDir, "the base Dir for kubekey. Default current dir. ")
|
||||||
gfs.BoolVar(&o.Debug, "debug", o.Debug, "Debug mode, after a successful execution of Pipeline, "+"will retain runtime data, which includes task execution status and parameters.")
|
gfs.BoolVar(&o.Debug, "debug", o.Debug, "Debug mode, after a successful execution of Pipeline, "+"will retain runtime data, which includes task execution status and parameters.")
|
||||||
cfs := fss.FlagSet("controller-manager")
|
cfs := fss.FlagSet("controller-manager")
|
||||||
cfs.IntVar(&o.MaxConcurrentReconciles, "max-concurrent-reconciles", o.MaxConcurrentReconciles, "The number of maximum concurrent reconciles for controller.")
|
cfs.IntVar(&o.MaxConcurrentReconciles, "max-concurrent-reconciles", o.MaxConcurrentReconciles, "The number of maximum concurrent reconciles for controller.")
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func newCommonOptions() commonOptions {
|
||||||
func (o *commonOptions) flags() cliflag.NamedFlagSets {
|
func (o *commonOptions) flags() cliflag.NamedFlagSets {
|
||||||
fss := cliflag.NamedFlagSets{}
|
fss := cliflag.NamedFlagSets{}
|
||||||
gfs := fss.FlagSet("generic")
|
gfs := fss.FlagSet("generic")
|
||||||
gfs.StringVar(&o.WorkDir, "work-dir", o.WorkDir, "the base Dir for kubekey. Default current dir. ")
|
gfs.StringVar(&o.WorkDir, "workdir", o.WorkDir, "the base Dir for kubekey. Default current dir. ")
|
||||||
gfs.StringVarP(&o.Artifact, "artifact", "a", "", "Path to a KubeKey artifact")
|
gfs.StringVarP(&o.Artifact, "artifact", "a", "", "Path to a KubeKey artifact")
|
||||||
gfs.StringVarP(&o.ConfigFile, "config", "c", o.ConfigFile, "the config file path. support *.yaml ")
|
gfs.StringVarP(&o.ConfigFile, "config", "c", o.ConfigFile, "the config file path. support *.yaml ")
|
||||||
gfs.StringArrayVar(&o.Set, "set", o.Set, "set value in config. format --set key=val or --set k1=v1,k2=v2")
|
gfs.StringArrayVar(&o.Set, "set", o.Set, "set value in config. format --set key=val or --set k1=v1,k2=v2")
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ func (o *PipelineOptions) Flags() cliflag.NamedFlagSets {
|
||||||
pfs := fss.FlagSet("pipeline flags")
|
pfs := fss.FlagSet("pipeline flags")
|
||||||
pfs.StringVar(&o.Name, "name", o.Name, "name of pipeline")
|
pfs.StringVar(&o.Name, "name", o.Name, "name of pipeline")
|
||||||
pfs.StringVarP(&o.Namespace, "namespace", "n", o.Namespace, "namespace of pipeline")
|
pfs.StringVarP(&o.Namespace, "namespace", "n", o.Namespace, "namespace of pipeline")
|
||||||
pfs.StringVar(&o.WorkDir, "work-dir", o.WorkDir, "the base Dir for kubekey. Default current dir. ")
|
pfs.StringVar(&o.WorkDir, "workdir", o.WorkDir, "the base Dir for kubekey. Default current dir. ")
|
||||||
|
|
||||||
return fss
|
return fss
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func (e pipelineExecutor) execBatchHosts(ctx context.Context, play kkprojectv1.P
|
||||||
}
|
}
|
||||||
// generate task from role
|
// generate task from role
|
||||||
for _, role := range play.Roles {
|
for _, role := range play.Roles {
|
||||||
if !role.Taggable.IsEnabled(e.pipeline.Spec.Tags, e.pipeline.Spec.SkipTags) {
|
if !kkprojectv1.JoinTag(role.Taggable, play.Taggable).IsEnabled(e.pipeline.Spec.Tags, e.pipeline.Spec.SkipTags) {
|
||||||
// if not match the tags. skip
|
// if not match the tags. skip
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue