mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +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
|
||||
tags: ["always"]
|
||||
roles:
|
||||
- init/init-artifact
|
||||
- init/init-cert
|
||||
- install/image-registry
|
||||
- role: init/init-artifact
|
||||
tags: ["always"]
|
||||
- role: init/init-cert
|
||||
tags: ["always"]
|
||||
- role: install/image-registry
|
||||
tags: ["always"]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
image_registry:
|
||||
# ha_vip: 192.168.122.59
|
||||
namespace_override: ""
|
||||
# which store images data which will push to registry.
|
||||
images_dir: /tmp/kubekey/images/
|
||||
auth:
|
||||
registry: |
|
||||
{{- if and .image_registry.ha_vip (ne .image_registry.ha_vip "") }}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@
|
|||
copy:
|
||||
src: |
|
||||
{{ .work_dir }}/kubekey/images/
|
||||
dest: /tmp/kubekey/images/
|
||||
dest: |
|
||||
{{ .image_registry.images_dir }}
|
||||
|
||||
- name: Create harbor project for each image
|
||||
tags: ["only_image"]
|
||||
command: |
|
||||
{{- 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
|
||||
# only deal with directories
|
||||
continue
|
||||
|
|
@ -18,24 +19,24 @@
|
|||
|
||||
project=${dir##*/}
|
||||
|
||||
if [ "$project" == "blobs" ]; then
|
||||
if [[ "$project" == "blobs" ]]; then
|
||||
# skip blobs dir
|
||||
continue
|
||||
fi
|
||||
|
||||
# if project is not exist, create if
|
||||
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}')
|
||||
if [ $http_code == 404 ]; then
|
||||
|
||||
# if project is not exist, create it
|
||||
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 echo "$resp" | grep -q '"code":"NOT_FOUND"'; then
|
||||
# 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
|
||||
done
|
||||
{{- else }}
|
||||
# if project is not exist, create if
|
||||
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}')
|
||||
if [ $http_code == 404 ]; then
|
||||
# if project is not exist, create it
|
||||
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 echo "$resp" | grep -q '"code":"NOT_FOUND"'; then
|
||||
# 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
|
||||
{{- end }}
|
||||
when: .image_registry.type | eq "harbor"
|
||||
|
|
@ -44,7 +45,8 @@
|
|||
tags: ["only_image"]
|
||||
image:
|
||||
push:
|
||||
images_dir: /tmp/kubekey/images/
|
||||
images_dir: |
|
||||
{{ .image_registry.images_dir }}
|
||||
registry: |
|
||||
{{ .image_registry.auth.registry }}
|
||||
namespace_override: |
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func NewControllerManagerServerOptions() *ControllerManagerServerOptions {
|
|||
func (o *ControllerManagerServerOptions) Flags() cliflag.NamedFlagSets {
|
||||
fss := cliflag.NamedFlagSets{}
|
||||
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.")
|
||||
cfs := fss.FlagSet("controller-manager")
|
||||
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 {
|
||||
fss := cliflag.NamedFlagSets{}
|
||||
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.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")
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func (o *PipelineOptions) Flags() cliflag.NamedFlagSets {
|
|||
pfs := fss.FlagSet("pipeline flags")
|
||||
pfs.StringVar(&o.Name, "name", o.Name, "name 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ func (e pipelineExecutor) execBatchHosts(ctx context.Context, play kkprojectv1.P
|
|||
}
|
||||
// generate task from role
|
||||
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
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue