Skip to content

Commit

Permalink
fix: test kk push image to harbor. (#2457)
Browse files Browse the repository at this point in the history
Co-authored-by: joyceliu <[email protected]>
  • Loading branch information
redscholar and joyceliu authored Nov 19, 2024
1 parent b79482a commit 3e56b09
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
9 changes: 6 additions & 3 deletions builtin/playbooks/artifact_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions builtin/roles/install/image-registry/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -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 "") }}
Expand Down
28 changes: 15 additions & 13 deletions builtin/roles/install/image-registry/tasks/load_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,39 @@
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
fi
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"
Expand All @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller-manager/app/options/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/kk/app/options/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/kk/app/options/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/executor/pipeline_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3e56b09

Please sign in to comment.