Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove promo flag and other dependent flags from the generatebundlefile CLI #1150

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 5 additions & 59 deletions generatebundlefile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

This binary reads an input file describing the curated packages to be included in the bundle then generates a bundle custom resource file. In addition, it has the ability to promote images and Helm charts between container registries.
This binary reads an input file describing the curated packages to be included in the bundle then generates a bundle custom resource file.

There are three types of helm version tags we can input:

Expand All @@ -23,15 +23,16 @@ make build
### Bundle Generation

To generate a signed bundle you need an AWS KMS key that is:

- Asymmetric
- ECC_NIST_P256
- Key Policy enabled for CLI user to have `kms:Sign` configured.
- Key Policy enabled for CLI user to have `kms:Sign` configured.

```sh
generatebundlefile --input data/sample_input.yaml --key alias/signingPackagesKey
```

This will output all the corresponding CRD's into `output/bundle.yaml`
This will output all the corresponding CRD's into `output/bundle.yaml`

#### Sample Bundle Generation

Expand All @@ -41,47 +42,11 @@ generatebundlefile --generate-sample

This will output a sample bundle file to ./output.


### Public Promotion to another Account

```sh
generatebundlefile --public-profile "profile-name" --input data/sample_input.yaml
```

This command will move **Only** the helm chart from the listed input files to the target **public** ECR in another account.

### Private Promotion to another Account

```sh
generatebundlefile --private-profile "profile-name" --input data/sample_input.yaml
```

This command will move **Only** the images from the listed helm charts in the input files to the target **private** ECR in another account.

### Package Promotion

To promote a package from a private ECR to public you need the repository name. This repository must contain a Helm chart built by the process in the eks-anywhere-build-tooling git repository.
This will **both** for the helm chart, and the imgaes required to the public ECR of the calling user.

To promote the latest helm chart from the private repository.

```sh
generatebundlefile --promote hello-eks-anywhere
```

To promote multiple versions of a helm chart in one command

```sh
generatebundlefile --promote hello-eks-anywhere --input data/promote.yaml
```

### Input File Supported Formats

Currently the following formats can be used as input files each of the following command flags.
Currently the following formats can be used as input files with each of the following command flags.

--key alias/signingPackagesKey
--private-profile
--public--profile

#### Private Registry

Expand Down Expand Up @@ -176,22 +141,3 @@ packages:
- name: 0.1.1-92904119e6e1bae35bf88663d0875259d42346f8
- name: latest
```


#### Public Profile with Image Copy

```yaml
name: "v1-22-1001"
kubernetesVersion: "1.22"
packages:
- org: aws-containers
projects:
- name: hello-eks-anywhere
copyimages: true
repository: hello-eks-anywhere
registry: public.ecr.aws/eks-anywhere
versions:
- name: 0.1.1-92904119e6e1bae35bf88663d0875259d42346f8
- name: latest

```
11 changes: 0 additions & 11 deletions generatebundlefile/buildspecs/buildspec.yml

This file was deleted.

24 changes: 0 additions & 24 deletions generatebundlefile/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,6 @@ func AddMetadata(s api.PackageBundleSpec, name string) *api.PackageBundle {
}
}

// IfSignature checks if a signature exsits on a Packagebundle
func IfSignature(bundle *api.PackageBundle) (bool, error) {
annotations := bundle.Annotations
if annotations != nil {
return true, nil
}
return false, nil
}

// CheckSignature checks if current signature is equal to signature to added as an annotation, and skips if they are the same.
func CheckSignature(bundle *api.PackageBundle, signature string) (bool, error) {
if signature == "" || bundle == nil {
return false, fmt.Errorf("either signature or bundle is missing, but are required")
}
annotations := map[string]string{
FullSignatureAnnotation: signature,
}
// If current signature on file isn't at the --signature input return false, otherwsie true
if annotations[FullSignatureAnnotation] != bundle.Annotations[FullSignatureAnnotation] {
return false, fmt.Errorf("A signature already exists on the input file signatue")
}
return true, nil
}

// GetBundleSignature calls KMS and retrieves a signature, then base64 decodes it and returns that back
func GetBundleSignature(ctx context.Context, bundle *api.PackageBundle, key string) (string, error) {
digest, _, err := sig.GetDigest(bundle, sig.EksaDomain)
Expand Down
132 changes: 0 additions & 132 deletions generatebundlefile/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,138 +190,6 @@ func TestNewPackageFromInput(t *testing.T) {
}
}

func TestIfSignature(t *testing.T) {
tests := []struct {
testname string
testbundle *api.PackageBundle
wantBool bool
}{
{
testname: "Test no annotations",
testbundle: &api.PackageBundle{
TypeMeta: metav1.TypeMeta{
Kind: api.PackageBundleKind,
APIVersion: api.SchemeBuilder.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "1.20",
Namespace: "eksa-packages",
},
},
wantBool: false,
},
{
testname: "Test with annotations",
testbundle: &api.PackageBundle{
TypeMeta: metav1.TypeMeta{
Kind: api.PackageBundleKind,
APIVersion: api.SchemeBuilder.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "1.20",
Namespace: "eksa-packages",
Annotations: map[string]string{
"eksa.aws.com/signature": "123",
},
},
},
wantBool: true,
},
}
for _, tc := range tests {
t.Run(tc.testname, func(tt *testing.T) {
got, err := IfSignature(tc.testbundle)
if err != nil {
tt.Fatalf("IfSignature() error = %v", err)
}
if got != tc.wantBool {
tt.Fatalf("IfSignature() = %#v\n\n\n, want %#v", got, tc.wantBool)
}
})
}
}

func TestCheckSignature(t *testing.T) {
tests := []struct {
testname string
testbundle *api.PackageBundle
signature string
wantBool bool
wantErr bool
}{
{
testname: "Test empty signature",
testbundle: &api.PackageBundle{
TypeMeta: metav1.TypeMeta{
Kind: api.PackageBundleKind,
APIVersion: api.SchemeBuilder.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "1.20",
Namespace: "eksa-packages",
},
},
signature: "",
wantErr: true,
},
{
testname: "Test empty Bundle",
testbundle: nil,
signature: "signature-123",
wantErr: true,
},
{
testname: "Test same signature",
testbundle: &api.PackageBundle{
TypeMeta: metav1.TypeMeta{
Kind: api.PackageBundleKind,
APIVersion: api.SchemeBuilder.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "1.20",
Namespace: "eksa-packages",
Annotations: map[string]string{
"eksa.aws.com/signature": "signature-123",
},
},
},
signature: "signature-123",
wantBool: true,
wantErr: false,
},
{
testname: "Test different signature",
testbundle: &api.PackageBundle{
TypeMeta: metav1.TypeMeta{
Kind: api.PackageBundleKind,
APIVersion: api.SchemeBuilder.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "1.20",
Namespace: "eksa-packages",
Annotations: map[string]string{
"eksa.aws.com/signature": "signature-456",
},
},
},
signature: "signature-123",
wantBool: false,
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.testname, func(tt *testing.T) {
got, err := CheckSignature(tc.testbundle, tc.signature)
if (err != nil) != tc.wantErr {
tt.Fatalf("CheckSignature() error = %v, wantErr %v", err, tc.wantErr)
}
if got != tc.wantBool {
tt.Fatalf("CheckSignature() = %#v\n\n\n, want %#v", got, tc.wantBool)
}
})
}
}

type mockPublicRegistryClientBundle struct {
err error
}
Expand Down
18 changes: 0 additions & 18 deletions generatebundlefile/bundle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ type SigningPackageBundle struct {
Status interface{} `json:"status,omitempty"`
}

// newSigningPackageBundle is api.PackageBundle using SigningObjectMeta instead of metav1.ObjectMeta
func newSigningPackageBundle(bundle *api.PackageBundle) *SigningPackageBundle {
return &SigningPackageBundle{
PackageBundle: bundle,
SigningObjectMeta: newSigningObjectMeta(&bundle.ObjectMeta),
Status: nil,
}
}

// SigningObjectMeta removes fields that shouldn't be included when signing.
type SigningObjectMeta struct {
*metav1.ObjectMeta
Expand All @@ -48,14 +39,6 @@ type SigningObjectMeta struct {
CreationTimestamp interface{} `json:"creationTimestamp,omitempty"`
}

// newSigningObjectMeta is metav1.ObjectMeta without the CreationTimestamp since it gets added the yaml as null otherwise.
func newSigningObjectMeta(meta *metav1.ObjectMeta) *SigningObjectMeta {
return &SigningObjectMeta{
ObjectMeta: meta,
CreationTimestamp: nil,
}
}

// Input is the schema for the input file
// +kubebuilder:object:root=true
// +kubebuilder:object:generate=false
Expand All @@ -82,7 +65,6 @@ type Project struct {
Repository string `json:"repository,omitempty"`
Versions []Tag `json:"versions,omitempty"`
WorkloadOnly bool `json:"workloadonly,omitempty"`
CopyImages bool `json:"copyimages,omitempty"`
}

// Tag is the release tag
Expand Down
39 changes: 0 additions & 39 deletions generatebundlefile/data/promote/autoscaler/promote.yaml

This file was deleted.

31 changes: 0 additions & 31 deletions generatebundlefile/data/promote/eks-anywhere-packages/promote.yaml

This file was deleted.

Loading
Loading