From 170d352d17fd8bf62ff15ea5e22c0c9e16f2f34e Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:54:06 -0300 Subject: [PATCH] draft --- .../v1beta2/pulp_resource_types.go | 49 +- .../v1beta2/zz_generated.deepcopy.go | 135 +++++ ...manager.pulpproject.org_pulpresources.yaml | 484 +++++++++++++++++- config/samples/pulpresource.yaml | 66 +++ controllers/pulp_resources/README.md | 76 ++- controllers/pulp_resources/constants.go | 11 +- controllers/pulp_resources/controller.go | 2 +- controllers/pulp_resources/pulp.go | 99 ++-- controllers/pulp_resources/utils.go | 69 +-- 9 files changed, 888 insertions(+), 103 deletions(-) create mode 100644 config/samples/pulpresource.yaml diff --git a/apis/repo-manager.pulpproject.org/v1beta2/pulp_resource_types.go b/apis/repo-manager.pulpproject.org/v1beta2/pulp_resource_types.go index e7c88813c..43dc3997e 100644 --- a/apis/repo-manager.pulpproject.org/v1beta2/pulp_resource_types.go +++ b/apis/repo-manager.pulpproject.org/v1beta2/pulp_resource_types.go @@ -25,11 +25,51 @@ import ( // PulpResourceSpec defines the desired state of PulpResource type PulpResourceSpec struct { ClientConfig *string `json:"client_config,omitempty"` + Ansible *PulpAnsiblePlugin `json:"ansible,omitempty"` Container *PulpContainerPlugin `json:"container,omitempty"` File *PulpFilePlugin `json:"file,omitempty"` RPM *PulpRPMPlugin `json:"rpm,omitempty"` } +type PulpAnsiblePlugin struct { + Repository *PulpAnsibleRepository `json:"repository,omitempty"` + Distribution *PulpAnsibleDistribution `json:"distribution,omitempty"` + RoleRemote *PulpAnsibleRoleRemote `json:"role_remote,omitempty"` + CollectionRemote *PulpAnsibleCollectionRemote `json:"collection_remote,omitempty"` + GitRemote *PulpAnsibleGitRemote `json:"git_remote,omitempty"` + Sync *bool `json:"sync,omitempty"` +} + +type PulpAnsibleRepository struct { + PulpCoreRepository `json:",inline"` + Gpgkey string `json:"gpgkey,omitempty"` + Private bool `json:"private,omitempty"` +} + +type PulpAnsibleDistribution struct { + PulpCoreDistribution `json:",inline"` + RepositoryVersion int `json:"repository_version,omitempty"` +} + +type PulpAnsibleRoleRemote struct { + PulpCoreRemote `json:",inline"` +} + +type PulpAnsibleCollectionRemote struct { + PulpCoreRemote `json:",inline"` + RequirementsFile string `json:"requirements_file,omitempty"` + AuthURL string `json:"auth_url,omitempty"` + Token string `json:"token,omitempty"` + SyncDependencies bool `json:"sync_dependencies,omitempty"` + SignedOnly bool `json:"signed_only,omitempty"` +} + +type PulpAnsibleGitRemote struct { + PulpCoreRemote `json:",inline"` + MetadataOnly bool `json:"metadata_only,omitempty"` + GitRef string `json:"git_ref,omitempty"` +} + type PulpContainerPlugin struct { Repository *PulpContainerRepository `json:"repository,omitempty"` Distribution *PulpContainerDistribution `json:"distribution,omitempty"` @@ -108,7 +148,7 @@ type PulpRPMRemote struct { type PulpCoreRepository struct { Description string `json:"description,omitempty"` Remote string `json:"remote,omitempty"` - RetainRepoVersions int `json:"retain-repo-versions,omitempty"` + RetainRepoVersions int `json:"retain_repo_versions,omitempty"` Labels map[string]string `json:"pulp_labels,omitempty"` Name string `json:"name"` } @@ -133,11 +173,11 @@ type PulpCoreRemote struct { ProxyPassword string `json:"proxy_password,omitempty"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` - ConnectionTimeout string `json:"connection_timeout,omitempty"` + ConnectionTimeout int `json:"connection_timeout,omitempty"` DownloadConcurrency int `json:"download_concurrency,omitempty"` RateLimit int `json:"rate_limit,omitempty"` - SockConnectTimeout string `json:"sock_connect_timeout,omitempty"` - SockReadTimeout string `json:"sock_read_timeout,omitempty"` + SockConnectTimeout int `json:"sock_connect_timeout,omitempty"` + SockReadTimeout int `json:"sock_read_timeout,omitempty"` MaxRetries int `json:"max_retries,omitempty"` Policy string `json:"policy,omitempty"` TotalTimeout string `json:"total_timeout,omitempty"` @@ -153,6 +193,7 @@ type PulpSync struct { // PulpResourceStatus defines the observed state of PulpResource type PulpResourceStatus struct { + Ansible *PulpAnsiblePlugin `json:"ansible,omitempty"` Container *PulpContainerPlugin `json:"container,omitempty"` File *PulpFilePlugin `json:"file,omitempty"` RPM *PulpRPMPlugin `json:"rpm,omitempty"` diff --git a/apis/repo-manager.pulpproject.org/v1beta2/zz_generated.deepcopy.go b/apis/repo-manager.pulpproject.org/v1beta2/zz_generated.deepcopy.go index 54a244603..792a06261 100644 --- a/apis/repo-manager.pulpproject.org/v1beta2/zz_generated.deepcopy.go +++ b/apis/repo-manager.pulpproject.org/v1beta2/zz_generated.deepcopy.go @@ -323,6 +323,131 @@ func (in *Pulp) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PulpAnsibleCollectionRemote) DeepCopyInto(out *PulpAnsibleCollectionRemote) { + *out = *in + in.PulpCoreRemote.DeepCopyInto(&out.PulpCoreRemote) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PulpAnsibleCollectionRemote. +func (in *PulpAnsibleCollectionRemote) DeepCopy() *PulpAnsibleCollectionRemote { + if in == nil { + return nil + } + out := new(PulpAnsibleCollectionRemote) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PulpAnsibleDistribution) DeepCopyInto(out *PulpAnsibleDistribution) { + *out = *in + in.PulpCoreDistribution.DeepCopyInto(&out.PulpCoreDistribution) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PulpAnsibleDistribution. +func (in *PulpAnsibleDistribution) DeepCopy() *PulpAnsibleDistribution { + if in == nil { + return nil + } + out := new(PulpAnsibleDistribution) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PulpAnsibleGitRemote) DeepCopyInto(out *PulpAnsibleGitRemote) { + *out = *in + in.PulpCoreRemote.DeepCopyInto(&out.PulpCoreRemote) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PulpAnsibleGitRemote. +func (in *PulpAnsibleGitRemote) DeepCopy() *PulpAnsibleGitRemote { + if in == nil { + return nil + } + out := new(PulpAnsibleGitRemote) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PulpAnsiblePlugin) DeepCopyInto(out *PulpAnsiblePlugin) { + *out = *in + if in.Repository != nil { + in, out := &in.Repository, &out.Repository + *out = new(PulpAnsibleRepository) + (*in).DeepCopyInto(*out) + } + if in.Distribution != nil { + in, out := &in.Distribution, &out.Distribution + *out = new(PulpAnsibleDistribution) + (*in).DeepCopyInto(*out) + } + if in.RoleRemote != nil { + in, out := &in.RoleRemote, &out.RoleRemote + *out = new(PulpAnsibleRoleRemote) + (*in).DeepCopyInto(*out) + } + if in.CollectionRemote != nil { + in, out := &in.CollectionRemote, &out.CollectionRemote + *out = new(PulpAnsibleCollectionRemote) + (*in).DeepCopyInto(*out) + } + if in.GitRemote != nil { + in, out := &in.GitRemote, &out.GitRemote + *out = new(PulpAnsibleGitRemote) + (*in).DeepCopyInto(*out) + } + if in.Sync != nil { + in, out := &in.Sync, &out.Sync + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PulpAnsiblePlugin. +func (in *PulpAnsiblePlugin) DeepCopy() *PulpAnsiblePlugin { + if in == nil { + return nil + } + out := new(PulpAnsiblePlugin) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PulpAnsibleRepository) DeepCopyInto(out *PulpAnsibleRepository) { + *out = *in + in.PulpCoreRepository.DeepCopyInto(&out.PulpCoreRepository) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PulpAnsibleRepository. +func (in *PulpAnsibleRepository) DeepCopy() *PulpAnsibleRepository { + if in == nil { + return nil + } + out := new(PulpAnsibleRepository) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PulpAnsibleRoleRemote) DeepCopyInto(out *PulpAnsibleRoleRemote) { + *out = *in + in.PulpCoreRemote.DeepCopyInto(&out.PulpCoreRemote) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PulpAnsibleRoleRemote. +func (in *PulpAnsibleRoleRemote) DeepCopy() *PulpAnsibleRoleRemote { + if in == nil { + return nil + } + out := new(PulpAnsibleRoleRemote) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PulpBackup) DeepCopyInto(out *PulpBackup) { *out = *in @@ -904,6 +1029,11 @@ func (in *PulpResourceSpec) DeepCopyInto(out *PulpResourceSpec) { *out = new(string) **out = **in } + if in.Ansible != nil { + in, out := &in.Ansible, &out.Ansible + *out = new(PulpAnsiblePlugin) + (*in).DeepCopyInto(*out) + } if in.Container != nil { in, out := &in.Container, &out.Container *out = new(PulpContainerPlugin) @@ -934,6 +1064,11 @@ func (in *PulpResourceSpec) DeepCopy() *PulpResourceSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PulpResourceStatus) DeepCopyInto(out *PulpResourceStatus) { *out = *in + if in.Ansible != nil { + in, out := &in.Ansible, &out.Ansible + *out = new(PulpAnsiblePlugin) + (*in).DeepCopyInto(*out) + } if in.Container != nil { in, out := &in.Container, &out.Container *out = new(PulpContainerPlugin) diff --git a/config/crd/bases/repo-manager.pulpproject.org_pulpresources.yaml b/config/crd/bases/repo-manager.pulpproject.org_pulpresources.yaml index c82b9ee68..cdbd95668 100644 --- a/config/crd/bases/repo-manager.pulpproject.org_pulpresources.yaml +++ b/config/crd/bases/repo-manager.pulpproject.org_pulpresources.yaml @@ -39,6 +39,224 @@ spec: spec: description: PulpResourceSpec defines the desired state of PulpResource properties: + ansible: + properties: + collection_remote: + properties: + auth_url: + type: string + ca_cert: + type: string + client_cert: + type: string + client_key: + type: string + connection_timeout: + type: integer + download_concurrency: + type: integer + headers: + items: + additionalProperties: + type: string + type: object + type: array + max_retries: + type: integer + name: + type: string + password: + type: string + policy: + type: string + proxy_password: + type: string + proxy_url: + type: string + proxy_username: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + rate_limit: + type: integer + requirements_file: + type: string + signed_only: + type: boolean + sock_connect_timeout: + type: integer + sock_read_timeout: + type: integer + sync_dependencies: + type: boolean + tls_validation: + type: boolean + token: + type: string + total_timeout: + type: string + url: + type: string + username: + type: string + required: + - name + type: object + distribution: + properties: + base_path: + type: string + content-guard: + type: string + name: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + repository: + type: string + repository_version: + type: integer + required: + - name + type: object + git_remote: + properties: + ca_cert: + type: string + client_cert: + type: string + client_key: + type: string + connection_timeout: + type: integer + download_concurrency: + type: integer + git_ref: + type: string + headers: + items: + additionalProperties: + type: string + type: object + type: array + max_retries: + type: integer + metadata_only: + type: boolean + name: + type: string + password: + type: string + policy: + type: string + proxy_password: + type: string + proxy_url: + type: string + proxy_username: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + rate_limit: + type: integer + sock_connect_timeout: + type: integer + sock_read_timeout: + type: integer + tls_validation: + type: boolean + total_timeout: + type: string + url: + type: string + username: + type: string + required: + - name + type: object + repository: + properties: + description: + type: string + gpgkey: + type: string + name: + type: string + private: + type: boolean + pulp_labels: + additionalProperties: + type: string + type: object + remote: + type: string + retain_repo_versions: + type: integer + required: + - name + type: object + role_remote: + properties: + ca_cert: + type: string + client_cert: + type: string + client_key: + type: string + connection_timeout: + type: integer + download_concurrency: + type: integer + headers: + items: + additionalProperties: + type: string + type: object + type: array + max_retries: + type: integer + name: + type: string + password: + type: string + policy: + type: string + proxy_password: + type: string + proxy_url: + type: string + proxy_username: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + rate_limit: + type: integer + sock_connect_timeout: + type: integer + sock_read_timeout: + type: integer + tls_validation: + type: boolean + total_timeout: + type: string + url: + type: string + username: + type: string + required: + - name + type: object + sync: + type: boolean + type: object client_config: type: string container: @@ -73,7 +291,7 @@ spec: client_key: type: string connection_timeout: - type: string + type: integer download_concurrency: type: integer exclude_tags: @@ -113,9 +331,9 @@ spec: sigstore: type: string sock_connect_timeout: - type: string + type: integer sock_read_timeout: - type: string + type: integer tls_validation: type: boolean total_timeout: @@ -141,7 +359,7 @@ spec: type: object remote: type: string - retain-repo-versions: + retain_repo_versions: type: integer required: - name @@ -179,7 +397,7 @@ spec: client_key: type: string connection_timeout: - type: string + type: integer download_concurrency: type: integer headers: @@ -209,9 +427,9 @@ spec: rate_limit: type: integer sock_connect_timeout: - type: string + type: integer sock_read_timeout: - type: string + type: integer tls_validation: type: boolean total_timeout: @@ -239,7 +457,7 @@ spec: type: object remote: type: string - retain-repo-versions: + retain_repo_versions: type: integer required: - name @@ -279,7 +497,7 @@ spec: client_key: type: string connection_timeout: - type: string + type: integer download_concurrency: type: integer headers: @@ -311,9 +529,9 @@ spec: sles_auth_token: type: string sock_connect_timeout: - type: string + type: integer sock_read_timeout: - type: string + type: integer tls_validation: type: boolean total_timeout: @@ -349,7 +567,7 @@ spec: type: string retain-package-vesions: type: integer - retain-repo-versions: + retain_repo_versions: type: integer required: - name @@ -361,6 +579,224 @@ spec: status: description: PulpResourceStatus defines the observed state of PulpResource properties: + ansible: + properties: + collection_remote: + properties: + auth_url: + type: string + ca_cert: + type: string + client_cert: + type: string + client_key: + type: string + connection_timeout: + type: integer + download_concurrency: + type: integer + headers: + items: + additionalProperties: + type: string + type: object + type: array + max_retries: + type: integer + name: + type: string + password: + type: string + policy: + type: string + proxy_password: + type: string + proxy_url: + type: string + proxy_username: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + rate_limit: + type: integer + requirements_file: + type: string + signed_only: + type: boolean + sock_connect_timeout: + type: integer + sock_read_timeout: + type: integer + sync_dependencies: + type: boolean + tls_validation: + type: boolean + token: + type: string + total_timeout: + type: string + url: + type: string + username: + type: string + required: + - name + type: object + distribution: + properties: + base_path: + type: string + content-guard: + type: string + name: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + repository: + type: string + repository_version: + type: integer + required: + - name + type: object + git_remote: + properties: + ca_cert: + type: string + client_cert: + type: string + client_key: + type: string + connection_timeout: + type: integer + download_concurrency: + type: integer + git_ref: + type: string + headers: + items: + additionalProperties: + type: string + type: object + type: array + max_retries: + type: integer + metadata_only: + type: boolean + name: + type: string + password: + type: string + policy: + type: string + proxy_password: + type: string + proxy_url: + type: string + proxy_username: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + rate_limit: + type: integer + sock_connect_timeout: + type: integer + sock_read_timeout: + type: integer + tls_validation: + type: boolean + total_timeout: + type: string + url: + type: string + username: + type: string + required: + - name + type: object + repository: + properties: + description: + type: string + gpgkey: + type: string + name: + type: string + private: + type: boolean + pulp_labels: + additionalProperties: + type: string + type: object + remote: + type: string + retain_repo_versions: + type: integer + required: + - name + type: object + role_remote: + properties: + ca_cert: + type: string + client_cert: + type: string + client_key: + type: string + connection_timeout: + type: integer + download_concurrency: + type: integer + headers: + items: + additionalProperties: + type: string + type: object + type: array + max_retries: + type: integer + name: + type: string + password: + type: string + policy: + type: string + proxy_password: + type: string + proxy_url: + type: string + proxy_username: + type: string + pulp_labels: + additionalProperties: + type: string + type: object + rate_limit: + type: integer + sock_connect_timeout: + type: integer + sock_read_timeout: + type: integer + tls_validation: + type: boolean + total_timeout: + type: string + url: + type: string + username: + type: string + required: + - name + type: object + sync: + type: boolean + type: object container: properties: distribution: @@ -393,7 +829,7 @@ spec: client_key: type: string connection_timeout: - type: string + type: integer download_concurrency: type: integer exclude_tags: @@ -433,9 +869,9 @@ spec: sigstore: type: string sock_connect_timeout: - type: string + type: integer sock_read_timeout: - type: string + type: integer tls_validation: type: boolean total_timeout: @@ -461,7 +897,7 @@ spec: type: object remote: type: string - retain-repo-versions: + retain_repo_versions: type: integer required: - name @@ -499,7 +935,7 @@ spec: client_key: type: string connection_timeout: - type: string + type: integer download_concurrency: type: integer headers: @@ -529,9 +965,9 @@ spec: rate_limit: type: integer sock_connect_timeout: - type: string + type: integer sock_read_timeout: - type: string + type: integer tls_validation: type: boolean total_timeout: @@ -559,7 +995,7 @@ spec: type: object remote: type: string - retain-repo-versions: + retain_repo_versions: type: integer required: - name @@ -599,7 +1035,7 @@ spec: client_key: type: string connection_timeout: - type: string + type: integer download_concurrency: type: integer headers: @@ -631,9 +1067,9 @@ spec: sles_auth_token: type: string sock_connect_timeout: - type: string + type: integer sock_read_timeout: - type: string + type: integer tls_validation: type: boolean total_timeout: @@ -669,7 +1105,7 @@ spec: type: string retain-package-vesions: type: integer - retain-repo-versions: + retain_repo_versions: type: integer required: - name diff --git a/config/samples/pulpresource.yaml b/config/samples/pulpresource.yaml new file mode 100644 index 000000000..70e73f5eb --- /dev/null +++ b/config/samples/pulpresource.yaml @@ -0,0 +1,66 @@ +### oc patch pulpresource pulp --type=merge -p '{"metadata": {"finalizers": null}}' +--- +apiVersion: v1 +kind: Secret +metadata: + name: 'client-config' +stringData: + username: 'admin' + password: 'password' + address: 'http://localhost:24880' +--- +apiVersion: repo-manager.pulpproject.org/v1beta2 +kind: PulpResource +metadata: + name: pulp +spec: + client_config: client-config + + ansible: + sync: true + repository: + name: test-ansible + distribution: + name: test-ansible + base_path: test-ansible + collection_remote: + name: test-ansible + url: "https://galaxy-dev.ansible.com/" + requirements_file: "collections:\n - testing.ansible_testing_content" + + file: + sync: true + repository: + name: test-file + autopublish: true + distribution: + name: test-file + base_path: test-file + remote: + name: test-file + url: 'https://fixtures.pulpproject.org/file/PULP_MANIFEST' + + container: + sync: true + repository: + name: test-container + distribution: + name: test-container + base_path: test-container + remote: + name: test-container + url: "https://ghcr.io" + upstream_name: pulp/test-fixture-1 + + rpm: + sync: true + repository: + name: test-rpm + autopublish: true + distribution: + name: test-rpm + base_path: test-rpm + remote: + name: test-rpm + url: 'https://fixtures.pulpproject.org/rpm-unsigned/' + policy: 'on_demand' diff --git a/controllers/pulp_resources/README.md b/controllers/pulp_resources/README.md index 2220213ad..752ab46ad 100644 --- a/controllers/pulp_resources/README.md +++ b/controllers/pulp_resources/README.md @@ -5,6 +5,11 @@ ### Sub Resources +* [PulpAnsibleCollectionRemote](#pulpansiblecollectionremote) +* [PulpAnsibleDistribution](#pulpansibledistribution) +* [PulpAnsibleGitRemote](#pulpansiblegitremote) +* [PulpAnsiblePlugin](#pulpansibleplugin) +* [PulpAnsibleRepository](#pulpansiblerepository) * [PulpContainerDistribution](#pulpcontainerdistribution) * [PulpContainerPlugin](#pulpcontainerplugin) * [PulpContainerRemote](#pulpcontainerremote) @@ -23,6 +28,67 @@ * [PulpResourceStatus](#pulpresourcestatus) * [PulpSync](#pulpsync) +#### PulpAnsibleCollectionRemote + + + +| Field | Description | Scheme | Required | +| ----- | ----------- | ------ | -------- | +| requirements_file | | string | false | +| auth_url | | string | false | +| token | | string | false | +| sync_dependencies | | bool | false | +| signed_only | | bool | false | + +[Back to Custom Resources](#custom-resources) + +#### PulpAnsibleDistribution + + + +| Field | Description | Scheme | Required | +| ----- | ----------- | ------ | -------- | +| repository_version | | int | false | + +[Back to Custom Resources](#custom-resources) + +#### PulpAnsibleGitRemote + + + +| Field | Description | Scheme | Required | +| ----- | ----------- | ------ | -------- | +| metadata_only | | bool | false | +| git_ref | | string | false | + +[Back to Custom Resources](#custom-resources) + +#### PulpAnsiblePlugin + + + +| Field | Description | Scheme | Required | +| ----- | ----------- | ------ | -------- | +| repository | | *[PulpAnsibleRepository](#pulpansiblerepository) | false | +| distribution | | *[PulpAnsibleDistribution](#pulpansibledistribution) | false | +| role_remote | | *[PulpAnsibleRoleRemote](#pulpansibleroleremote) | false | +| collection_remote | | *[PulpAnsibleCollectionRemote](#pulpansiblecollectionremote) | false | +| git_remote | | *[PulpAnsibleGitRemote](#pulpansiblegitremote) | false | +| sync | | *bool | false | + +[Back to Custom Resources](#custom-resources) + +#### PulpAnsibleRepository + + + +| Field | Description | Scheme | Required | +| ----- | ----------- | ------ | -------- | +| gpgkey | | string | false | +| private | | bool | false | + +[Back to Custom Resources](#custom-resources) + #### PulpContainerDistribution @@ -91,11 +157,11 @@ | proxy_password | | string | false | | username | | string | false | | password | | string | false | -| connection_timeout | | string | false | +| connection_timeout | | int | false | | download_concurrency | | int | false | | rate_limit | | int | false | -| sock_connect_timeout | | string | false | -| sock_read_timeout | | string | false | +| sock_connect_timeout | | int | false | +| sock_read_timeout | | int | false | | max_retries | | int | false | | policy | | string | false | | total_timeout | | string | false | @@ -112,7 +178,7 @@ | ----- | ----------- | ------ | -------- | | description | | string | false | | remote | | string | false | -| retain-repo-versions | | int | false | +| retain_repo_versions | | int | false | | pulp_labels | | map[string]string | false | | name | | string | true | @@ -231,6 +297,7 @@ PulpResourceSpec defines the desired state of PulpResource | Field | Description | Scheme | Required | | ----- | ----------- | ------ | -------- | | client_config | | *string | false | +| ansible | | *[PulpAnsiblePlugin](#pulpansibleplugin) | false | | container | | *[PulpContainerPlugin](#pulpcontainerplugin) | false | | file | | *[PulpFilePlugin](#pulpfileplugin) | false | | rpm | | *[PulpRPMPlugin](#pulprpmplugin) | false | @@ -243,6 +310,7 @@ PulpResourceStatus defines the observed state of PulpResource | Field | Description | Scheme | Required | | ----- | ----------- | ------ | -------- | +| ansible | | *[PulpAnsiblePlugin](#pulpansibleplugin) | false | | container | | *[PulpContainerPlugin](#pulpcontainerplugin) | false | | file | | *[PulpFilePlugin](#pulpfileplugin) | false | | rpm | | *[PulpRPMPlugin](#pulprpmplugin) | false | diff --git a/controllers/pulp_resources/constants.go b/controllers/pulp_resources/constants.go index e2b3d235d..dbe82b0b1 100644 --- a/controllers/pulp_resources/constants.go +++ b/controllers/pulp_resources/constants.go @@ -6,15 +6,20 @@ const ( PULP_ADMIN_USER = "admin" PULP_STATUS_ENDPOINT = "/pulp/api/v3/status/" + PULP_ANSIBLE_REPO_ENDPOINT = "/pulp/api/v3/repositories/ansible/ansible/" PULP_CONTAINER_REPO_ENDPOINT = "/pulp/api/v3/repositories/container/container/" PULP_FILE_REPO_ENDPOINT = "/pulp/api/v3/repositories/file/file/" PULP_RPM_REPO_ENDPOINT = "/pulp/api/v3/repositories/rpm/rpm/" + PULP_ANSIBLE_DISTRIBUTION_ENDPOINT = "/pulp/api/v3/distributions/ansible/ansible/" PULP_CONTAINER_DISTRIBUTION_ENDPOINT = "/pulp/api/v3/distributions/container/container/" PULP_FILE_DISTRIBUTION_ENDPOINT = "/pulp/api/v3/distributions/file/file/" PULP_RPM_DISTRIBUTION_ENDPOINT = "/pulp/api/v3/distributions/rpm/rpm/" - PULP_CONTAINER_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/container/container/" - PULP_FILE_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/file/file/" - PULP_RPM_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/rpm/rpm/" + PULP_ANSIBLE_COLLECTION_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/ansible/collection/" + PULP_ANSIBLE_GIT_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/ansible/git/" + PULP_ANSIBLE_ROLE_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/ansible/role/" + PULP_CONTAINER_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/container/container/" + PULP_FILE_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/file/file/" + PULP_RPM_REMOTE_ENDPOINT = "/pulp/api/v3/remotes/rpm/rpm/" ) diff --git a/controllers/pulp_resources/controller.go b/controllers/pulp_resources/controller.go index 852896018..9794be976 100644 --- a/controllers/pulp_resources/controller.go +++ b/controllers/pulp_resources/controller.go @@ -66,7 +66,7 @@ func (r *RepoManagerPulpResourceReconciler) Reconcile(ctx context.Context, req c r.syncPulpResources(pulpResource, pulpClient) r.pulpResourceFinalizer(ctx, *pulpResource, pulpClient) - if reconcile := r.update_status_fields(pulpResource, pulpClient); reconcile != nil { + if reconcile := r.updateStatusFields(pulpResource, pulpClient); reconcile != nil { return *reconcile, nil } log.Info("PulpResource " + pulpResource.Name + " synced") diff --git a/controllers/pulp_resources/pulp.go b/controllers/pulp_resources/pulp.go index b82fb3887..0d99243c6 100644 --- a/controllers/pulp_resources/pulp.go +++ b/controllers/pulp_resources/pulp.go @@ -32,23 +32,23 @@ func (r *RepoManagerPulpResourceReconciler) createPulpResources(pulpResource *re go func(pluginName string, resource map[string]string) { defer wg.Done() pluginField := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(pluginName) - if field_empty(pluginField) { + if fieldEmpty(pluginField) { return } - if is_status_plugin_equals_to_spec(pulpResource, pluginName) { + if isStatusPluginEqualsToSpec(pulpResource, pluginName) { return } for resourceType, endpoint := range resource { resourceValue := reflect.Indirect(pluginField).FieldByName(resourceType) - if field_empty(resourceValue) { + if fieldEmpty(resourceValue) { continue } resourceName := reflect.Indirect(resourceValue).FieldByName("Name").Interface().(string) - if response, exists := resource_exists(pulpClient, endpoint, resourceName); exists { + if response, exists := resourceExists(pulpClient, endpoint, resourceName); exists { // if already exists and responsebody is equal to what is in the spec, nothing to do // if already exists, but what we got from pulp is different from what is in the spec we need to update it - if !owned_by_operator(response, owner) { + if !ownedByOperator(response, owner) { log.Error(nil, pluginName+" "+resourceType+" "+resourceName+" already exists, but is not managed by Pulp operator!") continue } @@ -57,13 +57,13 @@ func (r *RepoManagerPulpResourceReconciler) createPulpResources(pulpResource *re } // temporarily set the labels to create pulp resoruces - set_operator_label_to_resource(operatorLabels, &resourceValue) - if _, err := make_request("POST", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resourceValue.Interface()); err != nil { + setOperatorLabelToResource(operatorLabels, &resourceValue) + if _, err := makeRequest("POST", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resourceValue.Interface()); err != nil { log.Error(err, "Failed to create "+pluginName+" "+resourceType+" "+resourceName) continue } // unset the labels to not populate status field with it - unset_operator_label_to_resource(&resourceValue) + unsetOperatorLabelToResource(&resourceValue) log.Info(pluginName + " " + resourceType + " " + resourceName + " created!") } }(plugin, resource) @@ -78,7 +78,7 @@ func deletePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou // make a request to get the pulp_href from the resource to be removed log.V(1).Info("Making a GET request to " + endpoint) - response, err := make_request("GET", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resourceNameToBeDeleted) + response, err := makeRequest("GET", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resourceNameToBeDeleted) if err != nil { log.Error(err, "Failed to make GET request to "+endpoint) } @@ -92,14 +92,14 @@ func deletePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou // if the resource is found, but is not owned by pulp-operator we should not touch it owner := pulpResourceOwner(*pulpResource) - if !owned_by_operator(response, owner) { + if !ownedByOperator(response, owner) { log.Error(nil, plugin+" "+resource+" "+resourceNameToBeDeleted+" already exists, but is not managed by Pulp operator!") return } // delete it log.V(1).Info("Making a DELETE request to " + pulp_href) - _, err = make_request("DELETE", pulpClient.Address+pulp_href, pulpClient.Username, pulpClient.Password, nil) + _, err = makeRequest("DELETE", pulpClient.Address+pulp_href, pulpClient.Username, pulpClient.Password, nil) if err != nil { pulpClient.Log.Error(err, "Failed to make DELETE request to "+pulp_href) } @@ -112,21 +112,21 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou statusField := reflect.ValueOf(*pulpResource).FieldByName("Status") // if status is not defined yet (first operator execution) we just return - if field_empty(statusField) { + if fieldEmpty(statusField) { return } // if status.plugin is not defined yet (no previous definition of this plugin) there is nothing to be done statusPluginField := statusField.Elem().FieldByName(plugin) - if field_empty(statusPluginField) { + if fieldEmpty(statusPluginField) { return } // if resource exists in status but not in spec, it means the user wants to remove a previously defined resource statusResourceField := statusPluginField.Elem().FieldByName(resource) specField := reflect.ValueOf(*pulpResource).FieldByName("Spec") - if !field_empty(statusResourceField) && - (field_empty(specField) || + if !fieldEmpty(statusResourceField) && + (fieldEmpty(specField) || specField.FieldByName(plugin).IsNil() || specField.FieldByName(plugin).Elem().FieldByName(resource).IsNil()) { deletePulpResource(pulpResource, plugin, resource, endpoint, pulpClient) @@ -135,7 +135,7 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou // if what is in status is equal to spec, we are up-to-date, so there is nothing to do specPluginField := specField.FieldByName(plugin) - if !field_empty(specPluginField) { + if !fieldEmpty(specPluginField) { specResourceField := specPluginField.Elem().FieldByName(resource) if reflect.DeepEqual(statusResourceField.Interface(), specResourceField.Interface()) { return @@ -143,8 +143,8 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou } // in the first execution there is no definition of the status, we just return - if field_empty(statusPluginField) || - field_empty(statusResourceField) { + if fieldEmpty(statusPluginField) || + fieldEmpty(statusResourceField) { return } @@ -152,7 +152,7 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou // make a request to get the pulp_href from the resource to be removed log.V(1).Info("Making a GET request to " + endpoint) - response, err := make_request("GET", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resourceNameToBeUpdated) + response, err := makeRequest("GET", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resourceNameToBeUpdated) if err != nil { log.Error(err, "Failed to make a GET request to "+endpoint) } @@ -166,7 +166,7 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou // if the resource is found, but is not owned by pulp-operator we should not touch it owner := pulpResourceOwner(*pulpResource) - if !owned_by_operator(response, owner) { + if !ownedByOperator(response, owner) { log.Error(nil, plugin+" "+resource+" "+resourceNameToBeUpdated+" already exists, but is not managed by Pulp operator!") return } @@ -176,7 +176,7 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou if statusResourceField.Elem().FieldByName("Name").String() != specResourceField.Elem().FieldByName("Name").String() { // delete it log.V(1).Info("Making a DELETE request to " + pulp_href) - _, err = make_request("DELETE", pulpClient.Address+pulp_href, pulpClient.Username, pulpClient.Password, nil) + _, err = makeRequest("DELETE", pulpClient.Address+pulp_href, pulpClient.Username, pulpClient.Password, nil) if err != nil { log.Error(err, "Failed to make DELETE request to "+pulp_href) } @@ -184,7 +184,7 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou } else { /// patch it log.V(1).Info("Making a PATCH request to " + pulp_href) - response, err = make_request("PATCH", pulpClient.Address+pulp_href, pulpClient.Username, pulpClient.Password, specResourceField.Elem().Interface()) + response, err = makeRequest("PATCH", pulpClient.Address+pulp_href, pulpClient.Username, pulpClient.Password, specResourceField.Elem().Interface()) if err != nil { log.Error(err, "Failed to make a PATCH request to "+pulp_href) } @@ -195,25 +195,48 @@ func updatePulpResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou func createSyncResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResource, plugin string, pulpClient pulpClient) { log, username, password, pulp_address := pulpClient.Log, pulpClient.Username, pulpClient.Password, pulpClient.Address + // ansible remotes don't follow the same pattern as the other plugins specRemoteField := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin).Elem().FieldByName("Remote") - if field_empty(specRemoteField) { + remoteType := "Remote" + if plugin == "Ansible" { + ansiblePlugin := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin).Elem() + + // only a single type of remote should be specified + // collection_remote is the one with less precedence + // git_remote has more priority than collection_remote + // role_remote is the one with the most priority + if !fieldEmpty(ansiblePlugin.FieldByName("CollectionRemote")) { + specRemoteField = ansiblePlugin.FieldByName("CollectionRemote") + remoteType = "CollectionRemote" + } + if !fieldEmpty(ansiblePlugin.FieldByName("GitRemote")) { + specRemoteField = ansiblePlugin.FieldByName("GitRemote") + remoteType = "GitRemote" + } + if !fieldEmpty(ansiblePlugin.FieldByName("RoleRemote")) { + specRemoteField = ansiblePlugin.FieldByName("RoleRemote") + remoteType = "RoleRemote" + } + } + + if fieldEmpty(specRemoteField) { log.Error(nil, "Sync enabled for "+plugin+" plugin without defining a remote.") return } specRepositoryField := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin).Elem().FieldByName("Repository") - if field_empty(specRepositoryField) { + if fieldEmpty(specRepositoryField) { log.Error(nil, "Sync enabled for "+plugin+" plugin without defining a repository.") return } specDistributionField := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin).Elem().FieldByName("Distribution") - if field_empty(specDistributionField) { + if fieldEmpty(specDistributionField) { log.Error(nil, "Sync enabled for "+plugin+" plugin without defining a distribution.") return } statusPluginField := reflect.ValueOf(*pulpResource).FieldByName("Status").Elem().FieldByName(plugin) - if !field_empty(statusPluginField) { - if reflect.DeepEqual(specRemoteField.Interface(), statusPluginField.Elem().FieldByName("Remote").Interface()) && + if !fieldEmpty(statusPluginField) { + if reflect.DeepEqual(specRemoteField.Interface(), statusPluginField.Elem().FieldByName(remoteType).Interface()) && reflect.DeepEqual(specRepositoryField.Interface(), statusPluginField.Elem().FieldByName("Repository").Interface()) && reflect.DeepEqual(specDistributionField.Interface(), statusPluginField.Elem().FieldByName("Distribution").Interface()) { log.V(1).Info("Already synced " + plugin + " plugin before, nothing to do") @@ -225,35 +248,35 @@ func createSyncResource(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResou specRemoteName := specRemoteField.Elem().FieldByName("Name").String() specDistributionName := specDistributionField.Elem().FieldByName("Name").String() - repositoryHref := get_pulp_href(plugin, "Repository", specRepositoryName, pulpClient) + repositoryHref := getPulpHref(plugin, "Repository", specRepositoryName, pulpClient) if repositoryHref == "" { return } - remoteHref := get_pulp_href(plugin, "Remote", specRemoteName, pulpClient) + remoteHref := getPulpHref(plugin, remoteType, specRemoteName, pulpClient) if remoteHref == "" { return } - distributionHref := get_pulp_href(plugin, "Distribution", specDistributionName, pulpClient) + distributionHref := getPulpHref(plugin, "Distribution", specDistributionName, pulpClient) if distributionHref == "" { return } repositoryRemoteBody := map[string]string{"remote": remoteHref} - _, err := make_request("PATCH", pulp_address+repositoryHref, username, password, repositoryRemoteBody) + _, err := makeRequest("PATCH", pulp_address+repositoryHref, username, password, repositoryRemoteBody) if err != nil { log.Error(err, "Failed to make a PATCH request to "+repositoryHref) } sync := repomanagerpulpprojectorgv1beta2.PulpSync{Remote: remoteHref, Mirror: false, SignedOnly: false} - _, err = make_request("POST", pulp_address+repositoryHref+"sync/", username, password, sync) + _, err = makeRequest("POST", pulp_address+repositoryHref+"sync/", username, password, sync) if err != nil { log.Error(err, "Failed to make a POST request to "+repositoryHref+"sync/") } distributionBody := map[string]string{"repository": repositoryHref} - _, err = make_request("PATCH", pulp_address+distributionHref, username, password, distributionBody) + _, err = makeRequest("PATCH", pulp_address+distributionHref, username, password, distributionBody) if err != nil { log.Error(err, "Failed to make a PATCH request to "+distributionHref) } @@ -265,12 +288,12 @@ func (r *RepoManagerPulpResourceReconciler) syncPulpResources(pulpResource *repo var wg sync.WaitGroup for plugin := range plugins { specPluginField := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin) - if field_empty(specPluginField) { + if fieldEmpty(specPluginField) { continue } specSyncField := specPluginField.Elem().FieldByName("Sync") - if field_empty(specSyncField) || + if fieldEmpty(specSyncField) || !specSyncField.Elem().Bool() { continue } @@ -284,17 +307,17 @@ func (r *RepoManagerPulpResourceReconciler) syncPulpResources(pulpResource *repo wg.Wait() } -func get_pulp_href(plugin, resourceType, resourceName string, pulpClient pulpClient) string { +func getPulpHref(plugin, resourceType, resourceName string, pulpClient pulpClient) string { log := pulpClient.Log // make a request to get the pulp_href from the resource to be synced resourceEndpoint := plugins[plugin][resourceType] log.V(1).Info("Making a GET request to " + resourceEndpoint) - response, err := make_request("GET", pulpClient.Address+resourceEndpoint, pulpClient.Username, pulpClient.Password, resourceName) + response, err := makeRequest("GET", pulpClient.Address+resourceEndpoint, pulpClient.Username, pulpClient.Password, resourceName) if err != nil { log.Error(err, "Failed to make a GET request to "+resourceEndpoint) } if response.Count == 0 { - log.Error(err, "Failed to find the "+plugin+" "+resourceType+" "+resourceName) + log.V(1).Info("Failed to find the " + plugin + " " + resourceType + " " + resourceName + ". Retrying ...") return "" } resourceHref := response.Results[0].(map[string]interface{})["pulp_href"].(string) diff --git a/controllers/pulp_resources/utils.go b/controllers/pulp_resources/utils.go index c59715877..927a920ea 100644 --- a/controllers/pulp_resources/utils.go +++ b/controllers/pulp_resources/utils.go @@ -29,6 +29,13 @@ var ( HTTP_NOT_FOUND = errors.New("404: Not Found") plugins = map[string]map[string]string{ + "Ansible": { + "Repository": PULP_ANSIBLE_REPO_ENDPOINT, + "Distribution": PULP_ANSIBLE_DISTRIBUTION_ENDPOINT, + "CollectionRemote": PULP_ANSIBLE_COLLECTION_REMOTE_ENDPOINT, + "GitRemote": PULP_ANSIBLE_GIT_REMOTE_ENDPOINT, + "RoleRemote": PULP_ANSIBLE_ROLE_REMOTE_ENDPOINT, + }, "Container": { "Repository": PULP_CONTAINER_REPO_ENDPOINT, "Distribution": PULP_CONTAINER_DISTRIBUTION_ENDPOINT, @@ -62,11 +69,11 @@ type responseBody struct { Results []any } -func get_api_svc(pulpName string) string { +func getApiSvc(pulpName string) string { return fmt.Sprintf("http://%s:24817", settings.ApiService(pulpName)) } -func get_credentials(ctx context.Context, r RepoManagerPulpResourceReconciler, pulpName, namespace string) string { +func getCredentials(ctx context.Context, r RepoManagerPulpResourceReconciler, pulpName, namespace string) string { pulp := &repomanagerpulpprojectorgv1beta2.Pulp{} r.Get(ctx, types.NamespacedName{Name: pulpName, Namespace: namespace}, pulp) @@ -77,7 +84,7 @@ func get_credentials(ctx context.Context, r RepoManagerPulpResourceReconciler, p return string(secret.Data["password"]) } -func make_request(method, addr, user, pass string, body any) (responseBody, error) { +func makeRequest(method, addr, user, pass string, body any) (responseBody, error) { // todo: this config should come from pulpClient client := &http.Client{ Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}, @@ -123,22 +130,22 @@ func make_request(method, addr, user, pass string, body any) (responseBody, erro return *response, nil } -// is_status_plugin_equals_to_spec compares the definitions of pulpresource.status and pulpresource.spec -func is_status_plugin_equals_to_spec(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResource, plugin string) bool { +// isStatusPluginEqualsToSpec compares the definitions of pulpresource.status and pulpresource.spec +func isStatusPluginEqualsToSpec(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResource, plugin string) bool { return reflect.DeepEqual( reflect.ValueOf(*pulpResource).FieldByName("Status").Elem().FieldByName(plugin).Interface(), reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin).Interface()) } -// field_empty checks is a pulpresource field is defined -func field_empty(field reflect.Value) bool { +// fieldEmpty checks is a pulpresource field is defined +func fieldEmpty(field reflect.Value) bool { return !field.IsValid() || field.IsZero() } -// resource_exists verifies if pulp resource already exists -func resource_exists(pulpClient pulpClient, endpoint string, resource any) (responseBody, bool) { +// resourceExists verifies if pulp resource already exists +func resourceExists(pulpClient pulpClient, endpoint string, resource any) (responseBody, bool) { // todo: pending handle errors (like 401, 403, etc) - response, err := make_request("GET", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resource) + response, err := makeRequest("GET", pulpClient.Address+endpoint, pulpClient.Username, pulpClient.Password, resource) if err != nil { pulpClient.Log.Error(err, "Failed to make GET request to "+endpoint) } @@ -148,18 +155,18 @@ func resource_exists(pulpClient pulpClient, endpoint string, resource any) (resp return response, false } -// set_operator_label_to_resource will set pulp resource with a label to help identifying it is an operator managed resource -func set_operator_label_to_resource(operatorLabels map[string]string, resourceValue *reflect.Value) { +// setOperatorLabelToResource will set pulp resource with a label to help identifying it is an operator managed resource +func setOperatorLabelToResource(operatorLabels map[string]string, resourceValue *reflect.Value) { reflect.Indirect(*resourceValue).FieldByName("Labels").Set(reflect.ValueOf(operatorLabels)) } -// unset_operator_label_to_resource will remove the resource labels definitions -func unset_operator_label_to_resource(resourceValue *reflect.Value) { +// unsetOperatorLabelToResource will remove the resource labels definitions +func unsetOperatorLabelToResource(resourceValue *reflect.Value) { reflect.Indirect(*resourceValue).FieldByName("Labels").Set(reflect.ValueOf(map[string]string{})) } -// create_status_fields creates the plugin and resource fields to be able to set them dinamically -func create_status_fields(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResource, plugin string, resource string) { +// createStatusFields creates the plugin and resource fields to be able to set them dinamically +func createStatusFields(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResource, plugin string, resource string) { pluginField := reflect.ValueOf(*pulpResource).FieldByName("Status").Elem().FieldByName(plugin) if pluginField.IsNil() { newField := reflect.New(reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin).Elem().Type()) @@ -172,16 +179,16 @@ func create_status_fields(pulpResource *repomanagerpulpprojectorgv1beta2.PulpRes } } -// owned_by_operator will check, from a response body, if the resource is managed by pulp operator -func owned_by_operator(response responseBody, owner string) bool { +// ownedByOperator will check, from a response body, if the resource is managed by pulp operator +func ownedByOperator(response responseBody, owner string) bool { return response.Results[0].(map[string]interface{})["pulp_labels"].(map[string]interface{})["owner"] == owner } func getClientConfig(ctx context.Context, r RepoManagerPulpResourceReconciler, pulpResource repomanagerpulpprojectorgv1beta2.PulpResource) pulpClient { pulpClient := pulpClient{ - Address: get_api_svc(pulpResource.Name), + Address: getApiSvc(pulpResource.Name), Username: PULP_ADMIN_USER, - Password: get_credentials(ctx, r, pulpResource.Name, pulpResource.Namespace), + Password: getCredentials(ctx, r, pulpResource.Name, pulpResource.Namespace), Log: r.RawLogger, Context: ctx, } @@ -196,7 +203,7 @@ func getClientConfig(ctx context.Context, r RepoManagerPulpResourceReconciler, p return pulpClient } -func (r RepoManagerPulpResourceReconciler) update_status_fields(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResource, pulpClient pulpClient) *ctrl.Result { +func (r RepoManagerPulpResourceReconciler) updateStatusFields(pulpResource *repomanagerpulpprojectorgv1beta2.PulpResource, pulpClient pulpClient) *ctrl.Result { var wg sync.WaitGroup for plugin, resource := range plugins { wg.Add(1) @@ -206,20 +213,22 @@ func (r RepoManagerPulpResourceReconciler) update_status_fields(pulpResource *re // remove the resource from status.plugin.resource if it was removed from spec.plugin.resource specPluginField := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin) statusPluginField := reflect.ValueOf(*pulpResource).FieldByName("Status").Elem().FieldByName(plugin) - if field_empty(specPluginField) { + if fieldEmpty(specPluginField) { statusPluginField.Set(reflect.Zero(statusPluginField.Type())) continue } - // remove the resource from status.plugin.resource if it was removed from spec.plugin.resource specResourceField := specPluginField.Elem().FieldByName(resourceType) - if field_empty(specResourceField) { - statusResourceField := statusPluginField.Elem().FieldByName(resourceType) - statusResourceField.Set(reflect.Zero(statusResourceField.Type())) + if fieldEmpty(specResourceField) { + // remove the resource from status.plugin.resource if it was removed from spec.plugin.resource + if !fieldEmpty(statusPluginField) { + statusResourceField := statusPluginField.Elem().FieldByName(resourceType) + statusResourceField.Set(reflect.Zero(statusResourceField.Type())) + } continue } - create_status_fields(pulpResource, pluginName, resourceType) + createStatusFields(pulpResource, pluginName, resourceType) statusPluginField.Elem().FieldByName(resourceType).Set(specResourceField) } }(plugin, resource) @@ -234,6 +243,7 @@ func (r RepoManagerPulpResourceReconciler) update_status_fields(pulpResource *re func pulpResourceOwner(pulpResource repomanagerpulpprojectorgv1beta2.PulpResource) string { return pulpResource.Namespace + "." + pulpResource.Name } + func operatorLabels(pulpResource repomanagerpulpprojectorgv1beta2.PulpResource) map[string]string { return map[string]string{ "owner": pulpResourceOwner(pulpResource), @@ -271,13 +281,13 @@ func (r *RepoManagerPulpResourceReconciler) finalizePulpResource(pulpResource *r for plugin, resource := range plugins { // nothing to do if there is nothing defined for this plugin pluginField := reflect.ValueOf(*pulpResource).FieldByName("Spec").FieldByName(plugin) - if field_empty(pluginField) { + if fieldEmpty(pluginField) { continue } for resourceType, endpoint := range resource { // nothing to do if there is nothing defined for this resource resourceValue := reflect.Indirect(pluginField).FieldByName(resourceType) - if field_empty(resourceValue) { + if fieldEmpty(resourceValue) { continue } deletePulpResource(pulpResource, plugin, resourceType, endpoint, pulpClient) @@ -317,6 +327,7 @@ func indexerFunc(obj client.Object) []string { return []string{} } +// TODO: remove this function and adapt makeRequest instead func validatePulpConnection(pulpClient pulpClient) error { client := &http.Client{