From 12f7597b0581bb1e2550eb0d71be4ee42ed4aa7e Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Tue, 5 Nov 2024 12:44:19 +0000 Subject: [PATCH] Fix rebase again --- .../v1alpha1/config.porch.kpt.dev_repositories.yaml | 13 +++++++++++++ api/porchconfig/v1alpha1/types.go | 13 +++++++++++++ api/porchconfig/v1alpha1/zz_generated.deepcopy.go | 5 +++++ pkg/cache/memory/cache.go | 9 +-------- test/e2e/cli/testdata/repo-register/config.yaml | 4 ++-- test/e2e/cli/testdata/rpkg-init-deploy/config.yaml | 4 ++-- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml b/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml index cc6905aa..d706a6f7 100644 --- a/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml +++ b/api/porchconfig/v1alpha1/config.porch.kpt.dev_repositories.yaml @@ -18,6 +18,9 @@ spec: - jsonPath: .spec.type name: Type type: string + - jsonPath: .spec.content + name: Content + type: string - jsonPath: .spec.deployment name: Deployment type: boolean @@ -56,6 +59,16 @@ spec: Notes: - deployment repository - in KRM API ConfigSync would be configured directly? (or via this API) properties: + content: + default: Package + description: |- + The Content field is deprecated, please do not specify it in new manifests. + For partial backward compatibility it is still recognized, but its only valid value is "Package", and if not specified its default value is also "Package". + type: string + x-kubernetes-validations: + - message: The 'content' field is deprecated, its only valid value + is 'Package' + rule: self == '' || self == 'Package' deployment: description: The repository is a deployment repository; final packages in this repository are deployment ready. diff --git a/api/porchconfig/v1alpha1/types.go b/api/porchconfig/v1alpha1/types.go index 9183465b..5c7239f1 100644 --- a/api/porchconfig/v1alpha1/types.go +++ b/api/porchconfig/v1alpha1/types.go @@ -22,6 +22,7 @@ import ( //+kubebuilder:subresource:status //+kubebuilder:resource:path=repositories,singular=repository //+kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type` +//+kubebuilder:printcolumn:name="Content",type=string,JSONPath=`.spec.content` //+kubebuilder:printcolumn:name="Deployment",type=boolean,JSONPath=`.spec.deployment` //+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=='Ready')].status` //+kubebuilder:printcolumn:name="Address",type=string,JSONPath=`.spec['git','oci']['repo','registry']` @@ -42,6 +43,12 @@ const ( RepositoryTypeOCI RepositoryType = "oci" ) +type RepositoryContent string + +const ( + RepositoryContentPackage RepositoryContent = "Package" +) + // RepositorySpec defines the desired state of Repository // // Notes: @@ -53,6 +60,12 @@ type RepositorySpec struct { Deployment bool `json:"deployment,omitempty"` // Type of the repository (i.e. git, OCI) Type RepositoryType `json:"type,omitempty"` + // The Content field is deprecated, please do not specify it in new manifests. + // For partial backward compatibility it is still recognized, but its only valid value is "Package", and if not specified its default value is also "Package". + // +kubebuilder:validation:XValidation:message="The 'content' field is deprecated, its only valid value is 'Package'",rule="self == '' || self == 'Package'" + // +kubebuilder:default="Package" + Content *RepositoryContent `json:"content,omitempty"` + // Git repository details. Required if `type` is `git`. Ignored if `type` is not `git`. Git *GitRepository `json:"git,omitempty"` // OCI repository details. Required if `type` is `oci`. Ignored if `type` is not `oci`. diff --git a/api/porchconfig/v1alpha1/zz_generated.deepcopy.go b/api/porchconfig/v1alpha1/zz_generated.deepcopy.go index d8d641b0..b637beb4 100644 --- a/api/porchconfig/v1alpha1/zz_generated.deepcopy.go +++ b/api/porchconfig/v1alpha1/zz_generated.deepcopy.go @@ -154,6 +154,11 @@ func (in *RepositoryRef) DeepCopy() *RepositoryRef { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RepositorySpec) DeepCopyInto(out *RepositorySpec) { *out = *in + if in.Content != nil { + in, out := &in.Content, &out.Content + *out = new(RepositoryContent) + **out = **in + } if in.Git != nil { in, out := &in.Git, &out.Git *out = new(GitRepository) diff --git a/pkg/cache/memory/cache.go b/pkg/cache/memory/cache.go index e1c8caeb..1961c41d 100644 --- a/pkg/cache/memory/cache.go +++ b/pkg/cache/memory/cache.go @@ -127,7 +127,7 @@ func (c *Cache) OpenRepository(ctx context.Context, repositorySpec *configapi.Re return nil, err } - r, err := oci.OpenRepository(repositorySpec.Name, repositorySpec.Namespace, repositorySpec.Spec.Content, ociSpec, repositorySpec.Spec.Deployment, storage) + r, err := oci.OpenRepository(repositorySpec.Name, repositorySpec.Namespace, ociSpec, repositorySpec.Spec.Deployment, storage) if err != nil { return nil, err } @@ -138,9 +138,6 @@ func (c *Cache) OpenRepository(ctx context.Context, repositorySpec *configapi.Re case configapi.RepositoryTypeGit: gitSpec := repositorySpec.Spec.Git - if !isPackageContent(repositorySpec.Spec.Content) { - return nil, fmt.Errorf("git repository supports Package content only; got %q", string(repositorySpec.Spec.Content)) - } if cachedRepo == nil { var mbs git.MainBranchStrategy if gitSpec.CreateBranch { @@ -174,10 +171,6 @@ func (c *Cache) OpenRepository(ctx context.Context, repositorySpec *configapi.Re } } -func isPackageContent(content configapi.RepositoryContent) bool { - return content == configapi.RepositoryContentPackage -} - func (c *Cache) CloseRepository(repositorySpec *configapi.Repository, allRepos []configapi.Repository) error { key, err := getCacheKey(repositorySpec) if err != nil { diff --git a/test/e2e/cli/testdata/repo-register/config.yaml b/test/e2e/cli/testdata/repo-register/config.yaml index 8fda8945..5e903814 100644 --- a/test/e2e/cli/testdata/repo-register/config.yaml +++ b/test/e2e/cli/testdata/repo-register/config.yaml @@ -31,8 +31,8 @@ commands: - get - --namespace=repo-register stdout: | - NAME TYPE DEPLOYMENT READY ADDRESS - test-blueprints git True https://github.com/platkrm/test-blueprints.git + NAME TYPE CONTENT DEPLOYMENT READY ADDRESS + test-blueprints git Package True https://github.com/platkrm/test-blueprints.git - args: - porchctl - repo diff --git a/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml b/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml index a5fbc814..33080679 100644 --- a/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml +++ b/test/e2e/cli/testdata/rpkg-init-deploy/config.yaml @@ -87,5 +87,5 @@ commands: - get - --namespace=rpkg-init-deploy stdout: | - NAME TYPE DEPLOYMENT READY ADDRESS - git git true True http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init-deploy + NAME TYPE CONTENT DEPLOYMENT READY ADDRESS + git git Package true True http://git-server.test-git-namespace.svc.cluster.local:8080/rpkg-init-deploy