Skip to content

Commit

Permalink
Removes default value for the build history limit
Browse files Browse the repository at this point in the history
Signed-off-by: Caroline Scherf <[email protected]>
  • Loading branch information
fcaroline2020 committed Aug 29, 2023
1 parent 53eabad commit abfac5a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 65 deletions.
2 changes: 2 additions & 0 deletions docs/kp_image_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ kp image create my-image --tag my-registry.com/my-repo --blob https://my-blob-ho
resource with generated container image references. A "kubectl apply -f" of the
resource from --output without image uploads will result in a reconcile failure.
-e, --env stringArray build time environment variables
--failed-build-history-limit string set the failedBuildHistoryLimit
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for create
Expand All @@ -77,6 +78,7 @@ kp image create my-image --tag my-registry.com/my-repo --blob https://my-blob-ho
--service-account string service account name to use (default "default")
-s, --service-binding stringArray build time service bindings
--sub-path string build code at the sub path located within the source code directory
--success-build-history-limit string set the successBuildHistoryLimit
-t, --tag string registry location where the OCI image will be created
-w, --wait wait for image create to be reconciled and tail resulting build logs
```
Expand Down
4 changes: 2 additions & 2 deletions docs/kp_image_patch.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ kp image patch my-image --tag my-registry.com/my-repo --blob https://my-blob-hos
resource with generated container image references. A "kubectl apply -f" of the
resource from --output without image uploads will result in a reconcile failure.
-e, --env stringArray build time environment variables to add/replace
--failed-build-history-limit int set the failedBuildHistoryLimit (default 10) (default 10)
--failed-build-history-limit string set the failedBuildHistoryLimit
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for patch
Expand All @@ -80,7 +80,7 @@ kp image patch my-image --tag my-registry.com/my-repo --blob https://my-blob-hos
--service-account string service account name to use
-s, --service-binding stringArray build time service bindings to add/replace
--sub-path string build code at the sub path located within the source code directory
--success-build-history-limit int set the successBuildHistoryLimit (default 10) (default 10)
--success-build-history-limit string set the successBuildHistoryLimit
-w, --wait wait for image resource patch to be reconciled and tail resulting build logs
```

Expand Down
2 changes: 2 additions & 0 deletions docs/kp_image_save.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ kp image save my-image --tag my-registry.com/my-repo --blob https://my-blob-host
resource with generated container image references. A "kubectl apply -f" of the
resource from --output without image uploads will result in a reconcile failure.
-e, --env stringArray build time environment variables
--failed-build-history-limit string set the failedBuildHistoryLimit
--git string git repository url
--git-revision string git revision such as commit, tag, or branch (default "main")
-h, --help help for save
Expand All @@ -83,6 +84,7 @@ kp image save my-image --tag my-registry.com/my-repo --blob https://my-blob-host
--service-account string service account name to use
-s, --service-binding stringArray build time service bindings to add/replace
--sub-path string build code at the sub path located within the source code directory
--success-build-history-limit string set the successBuildHistoryLimit
-t, --tag string registry location where the image will be created
-w, --wait wait for image create to be reconciled and tail resulting build logs
```
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/image/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ kp image create my-image --tag my-registry.com/my-repo --blob https://my-blob-ho
cmd.Flags().StringArrayVarP(&factory.Env, "env", "e", []string{}, "build time environment variables")
cmd.Flags().StringArrayVarP(&factory.ServiceBinding, "service-binding", "s", []string{}, "build time service bindings")
cmd.Flags().StringVar(&factory.CacheSize, "cache-size", "", "cache size as a kubernetes quantity (default \"2G\")")
cmd.Flags().Int64Var(&factory.SuccessBuildHistoryLimit, "success-build-history-limit", int64(10), "set the successBuildHistoryLimit (default 10)")
cmd.Flags().Int64Var(&factory.FailedBuildHistoryLimit, "failed-build-history-limit", int64(10), "set the failedBuildHistoryLimit (default 10)")
cmd.Flags().StringVar(&factory.SuccessBuildHistoryLimit, "success-build-history-limit", "", "set the successBuildHistoryLimit")
cmd.Flags().StringVar(&factory.FailedBuildHistoryLimit, "failed-build-history-limit", "", "set the failedBuildHistoryLimit")
cmd.Flags().StringVar(&factory.ServiceAccount, "service-account", "default", "service account name to use")
cmd.Flags().BoolP("wait", "w", false, "wait for image create to be reconciled and tail resulting build logs")
commands.SetImgUploadDryRunOutputFlags(cmd)
Expand Down
57 changes: 37 additions & 20 deletions pkg/commands/image/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package image_test

import (
"encoding/json"
registryfakes "github.com/vmware-tanzu/kpack-cli/pkg/registry/fakes"
"strconv"
"testing"

registryfakes "github.com/vmware-tanzu/kpack-cli/pkg/registry/fakes"

"github.com/pivotal/kpack/pkg/apis/build/v1alpha2"
corev1alpha1 "github.com/pivotal/kpack/pkg/apis/core/v1alpha1"
"github.com/pivotal/kpack/pkg/client/clientset/versioned/fake"
Expand Down Expand Up @@ -43,8 +45,6 @@ func setLastAppliedAnnotation(i *v1alpha2.Image) error {
func testCreateCommand(imageCommand func(clientSetProvider k8s.ClientSetProvider, rup registry.UtilProvider, newImageWaiter func(k8s.ClientSet) imgcmds.ImageWaiter) *cobra.Command) func(t *testing.T, when spec.G, it spec.S) {
return func(t *testing.T, when spec.G, it spec.S) {
const defaultNamespace = "some-default-namespace"
BuildHistoryLimit := int64(10)
defaultBuildHistoryLimit := &BuildHistoryLimit

registryUtilProvider := registryfakes.UtilProvider{}
fakeImageWaiter := &cmdFakes.FakeImageWaiter{}
Expand Down Expand Up @@ -109,8 +109,6 @@ func testCreateCommand(imageCommand func(clientSetProvider k8s.ClientSetProvider
Size: &cacheSize,
},
},
SuccessBuildHistoryLimit: defaultBuildHistoryLimit,
FailedBuildHistoryLimit: defaultBuildHistoryLimit,
},
}

Expand Down Expand Up @@ -251,8 +249,6 @@ Image Resource "some-image" created
},
SubPath: "some-sub-path",
},
SuccessBuildHistoryLimit: defaultBuildHistoryLimit,
FailedBuildHistoryLimit: defaultBuildHistoryLimit,
Build: &v1alpha2.ImageBuild{
Env: []corev1.EnvVar{
{
Expand Down Expand Up @@ -315,10 +311,9 @@ Image Resource "some-image" created

when("build history limits are provided", func() {
when("the image config is valid", func() {
it("creates the image", func() {
it("creates the image with build history limits", func() {
buildHistoryLimit := int64(5)
success := &buildHistoryLimit
failed := &buildHistoryLimit
defaultBuildHistoryLimit := &buildHistoryLimit

expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Expand All @@ -344,6 +339,8 @@ Image Resource "some-image" created
},
SubPath: "some-sub-path",
},
SuccessBuildHistoryLimit: defaultBuildHistoryLimit,
FailedBuildHistoryLimit: defaultBuildHistoryLimit,
Build: &v1alpha2.ImageBuild{
Env: []corev1.EnvVar{
{
Expand All @@ -359,8 +356,6 @@ Image Resource "some-image" created
},
},
},
SuccessBuildHistoryLimit: success,
FailedBuildHistoryLimit: failed,
},
}

Expand Down Expand Up @@ -448,8 +443,6 @@ Image Resource "some-image" created
},
},
},
SuccessBuildHistoryLimit: defaultBuildHistoryLimit,
FailedBuildHistoryLimit: defaultBuildHistoryLimit,
},
}
require.NoError(t, setLastAppliedAnnotation(expectedImage))
Expand Down Expand Up @@ -544,6 +537,9 @@ Image Resource "some-image" created

when("the image uses a non-default builder", func() {
it("uploads the source image and creates the image config", func() {
buildHistoryLimit := int64(10)
defaultBuildHistoryLimit := &buildHistoryLimit

expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Kind: "Image",
Expand Down Expand Up @@ -580,6 +576,8 @@ Image Resource "some-image" created
"--tag", "some-registry.io/some-repo",
"--blob", "some-blob",
"--builder", "some-builder",
"--success-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--failed-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
},
ExpectedOutput: `Creating Image Resource...
Image Resource "some-image" created
Expand All @@ -595,6 +593,9 @@ Image Resource "some-image" created

when("the image uses a non-default cluster builder", func() {
it("uploads the source image and creates the image config", func() {
buildHistoryLimit := int64(5)
defaultBuildHistoryLimit := &buildHistoryLimit

expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Kind: "Image",
Expand Down Expand Up @@ -630,6 +631,8 @@ Image Resource "some-image" created
"--tag", "some-registry.io/some-repo",
"--blob", "some-blob",
"--cluster-builder", "some-builder",
"--success-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--failed-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
},
ExpectedOutput: `Creating Image Resource...
Image Resource "some-image" created
Expand Down Expand Up @@ -668,9 +671,7 @@ Image Resource "some-image" created
Revision: "some-git-rev",
},
},
Build: &v1alpha2.ImageBuild{},
SuccessBuildHistoryLimit: defaultBuildHistoryLimit,
FailedBuildHistoryLimit: defaultBuildHistoryLimit,
Build: &v1alpha2.ImageBuild{},
},
}
require.NoError(t, setLastAppliedAnnotation(expectedImage))
Expand Down Expand Up @@ -715,6 +716,9 @@ Image Resource "some-image" created
})

when("the image config is valid", func() {
buildHistoryLimit := int64(10)
defaultBuildHistoryLimit := &buildHistoryLimit

expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Kind: "Image",
Expand Down Expand Up @@ -803,6 +807,8 @@ status: {}
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
"--success-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--failed-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--output", "yaml",
"--wait",
},
Expand All @@ -817,6 +823,8 @@ status: {}
})

it("can output in json format and does not wait", func() {
buildHistoryLimit := int64(10)

require.NoError(t, setLastAppliedAnnotation(expectedImage))
const resourceJSON = `{
"kind": "Image",
Expand Down Expand Up @@ -875,6 +883,8 @@ status: {}
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
"--success-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--failed-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--output", "json",
"--wait",
},
Expand Down Expand Up @@ -909,6 +919,7 @@ status: {}

when("the image config is valid", func() {
it("does not creates an image and prints result message with dry run indicated", func() {
buildHistoryLimit := int64(10)
testhelpers.CommandTest{
Args: []string{
"some-image",
Expand All @@ -918,6 +929,8 @@ status: {}
"--sub-path", "some-sub-path",
"--service-binding", "SomeResource:v1:some-binding",
"--env", "some-key=some-val",
"--success-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--failed-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--dry-run",
"--wait",
},
Expand All @@ -930,6 +943,7 @@ Image Resource "some-image" created (dry run)

when("output flag is used", func() {
it("does not create an image and prints the resource output", func() {
buildHistoryLimit := int64(10)
const resourceYAML = `apiVersion: kpack.io/v1alpha2
kind: Image
metadata:
Expand Down Expand Up @@ -972,6 +986,8 @@ status: {}
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
"--success-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--failed-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--output", "yaml",
"--dry-run",
"--wait",
Expand Down Expand Up @@ -1028,6 +1044,7 @@ Image Resource "some-image" created (dry run with image upload)

when("output flag is used", func() {
it("does not create an image and prints the resource output", func() {
buildHistoryLimit := int64(10)
const resourceYAML = `apiVersion: kpack.io/v1alpha2
kind: Image
metadata:
Expand Down Expand Up @@ -1070,6 +1087,8 @@ status: {}
"--sub-path", "some-sub-path",
"--env", "some-key=some-val",
"--service-binding", "SomeResource:v1:some-binding",
"--success-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--failed-build-history-limit", strconv.FormatInt(buildHistoryLimit, 10),
"--output", "yaml",
"--dry-run-with-image-upload",
"--wait",
Expand All @@ -1086,7 +1105,7 @@ status: {}

when("cache size is not provided", func() {
it("does not set an empty field on the image", func() {
//note: this is to allow for defaults to be set by kpack webhook
// note: this is to allow for defaults to be set by kpack webhook

expectedImage := &v1alpha2.Image{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -1127,8 +1146,6 @@ status: {}
},
},
},
SuccessBuildHistoryLimit: defaultBuildHistoryLimit,
FailedBuildHistoryLimit: defaultBuildHistoryLimit,
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/image/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ kp image patch my-image --tag my-registry.com/my-repo --blob https://my-blob-hos
cmd.Flags().StringArrayVarP(&factory.ServiceBinding, "service-binding", "s", []string{}, "build time service bindings to add/replace")
cmd.Flags().StringArrayVarP(&factory.DeleteServiceBinding, "delete-service-binding", "", []string{}, "build time service bindings to remove")
cmd.Flags().StringVar(&factory.CacheSize, "cache-size", "", "cache size as a kubernetes quantity")
cmd.Flags().Int64Var(&factory.SuccessBuildHistoryLimit, "success-build-history-limit", int64(10), "set the successBuildHistoryLimit (default 10)")
cmd.Flags().Int64Var(&factory.FailedBuildHistoryLimit, "failed-build-history-limit", int64(10), "set the failedBuildHistoryLimit (default 10)")
cmd.Flags().StringVar(&factory.SuccessBuildHistoryLimit, "success-build-history-limit", "", "set the successBuildHistoryLimit")
cmd.Flags().StringVar(&factory.FailedBuildHistoryLimit, "failed-build-history-limit", "", "set the failedBuildHistoryLimit")
cmd.Flags().StringVar(&factory.ServiceAccount, "service-account", "", "service account name to use")
cmd.Flags().BoolP("wait", "w", false, "wait for image resource patch to be reconciled and tail resulting build logs")
commands.SetImgUploadDryRunOutputFlags(cmd)
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/image/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ kp image save my-image --tag my-registry.com/my-repo --blob https://my-blob-host
cmd.Flags().StringVar(&factory.LocalPathDestinationImage, "local-path-destination-image", "", "registry location of where the local source code will be uploaded to (default \"<image-tag-repo>-source\")")
cmd.Flags().StringVar(&subPath, "sub-path", "", "build code at the sub path located within the source code directory")
cmd.Flags().StringVar(&factory.CacheSize, "cache-size", "", "cache size as a kubernetes quantity (default \"2G\")")
cmd.Flags().Int64Var(&factory.SuccessBuildHistoryLimit, "success-build-history-limit", int64(10), "set the successBuildHistoryLimit (default 10)")
cmd.Flags().Int64Var(&factory.FailedBuildHistoryLimit, "failed-build-history-limit", int64(10), "set the failedBuildHistoryLimit (default 10)")
cmd.Flags().StringVar(&factory.SuccessBuildHistoryLimit, "success-build-history-limit", "", "set the successBuildHistoryLimit")
cmd.Flags().StringVar(&factory.FailedBuildHistoryLimit, "failed-build-history-limit", "", "set the failedBuildHistoryLimit")
cmd.Flags().StringVarP(&factory.Builder, "builder", "b", "", "builder name")
cmd.Flags().StringVarP(&factory.ClusterBuilder, "cluster-builder", "c", "", "cluster builder name")
cmd.Flags().StringArrayVarP(&factory.Env, "env", "e", []string{}, "build time environment variables")
Expand Down
Loading

0 comments on commit abfac5a

Please sign in to comment.