Skip to content

Commit

Permalink
Solutions for kosli-dev/server#881 and kosli-dev/server#885
Browse files Browse the repository at this point in the history
Add exclude to every command when kosli can automatically calculate sha
Always resolve given revision to git commit - accepts shas, tags, branch names, HEAD...
  • Loading branch information
Ewelina Wilkosz committed Sep 1, 2023
1 parent 3658efe commit cff82cd
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions charts/k8s-reporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter
| kosliApiToken.secretKey | string | `""` | the name of the key in the secret data which contains the kosli API token |
| kosliApiToken.secretName | string | `""` | the name of the secret containing the kosli API token |
| nameOverride | string | `""` | overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one |
| podAnnotations | object | `{}` | |
| podAnnotations | object | `{}` | any custom annotations to be added to the cronjob |
| reporterConfig.dryRun | bool | `false` | whether the dry run mode is enabled or not. In dry run mode, the reporter logs the reports to stdout and does not send them to kosli. |
| reporterConfig.kosliEnvironmentName | string | `""` | the name of kosli environment that the k8s cluster/namespace correlates to |
| reporterConfig.kosliOrg | string | `""` | the name of the kosli org |
Expand All @@ -74,5 +74,5 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter
| serviceAccount.name | string | `""` | the name of the service account to use. If not set and create is true, a name is generated using the fullname template |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0)
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)

10 changes: 9 additions & 1 deletion cmd/kosli/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@ func newFingerprintCmd(out io.Writer) *cobra.Command {
}

addFingerprintFlags(cmd, o)
cmd.Flags().StringSliceVarP(&o.excludePaths, "exclude", "e", []string{}, excludePathsFlag)
cmd.Flags().StringSliceVarP(&o.excludePaths, "e", "e", []string{}, excludePathsFlag)
err := RequireFlags(cmd, []string{"artifact-type"})
if err != nil {
logger.Error("failed to configure required flags: %v", err)
}

err = DeprecateFlags(cmd, map[string]string{
"e": "use -x instead",
})
if err != nil {
logger.Error("failed to configure deprecated flags: %v", err)
}

return cmd
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/kosli/fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func (suite *FingerprintTestSuite) TestFingerprintCmd() {
{
name: "dir fingerprint",
cmd: "fingerprint --artifact-type dir testdata/folder1",
golden: "c43808cb04c6e66c4c6fc1f972dd67c3b9b71c81e0a0c78730da3699922d17be\n",
},
{
name: "dir fingerprint with exclude",
cmd: "fingerprint --artifact-type dir testdata/folder1 -x folder2",
golden: "773fd3300860454a2b065c5912c03008adb11e6a6dcf7c1c64c094ceab8f430a\n",
},
{
Expand Down
1 change: 1 addition & 0 deletions cmd/kosli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func addFingerprintFlags(cmd *cobra.Command, o *fingerprintOptions) {
cmd.Flags().StringVar(&o.registryProvider, "registry-provider", "", registryProviderFlag)
cmd.Flags().StringVar(&o.registryUsername, "registry-username", "", registryUsernameFlag)
cmd.Flags().StringVar(&o.registryPassword, "registry-password", "", registryPasswordFlag)
cmd.Flags().StringSliceVarP(&o.excludePaths, "exclude", "x", []string{}, excludePathsFlag)
}

func addAWSAuthFlags(cmd *cobra.Command, o *aws.AWSStaticCreds) {
Expand Down
12 changes: 11 additions & 1 deletion cmd/kosli/reportArtifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
type reportArtifactOptions struct {
fingerprintOptions *fingerprintOptions
flowName string
gitReference string
srcRepoRoot string
payload ArtifactPayload
}
Expand Down Expand Up @@ -84,11 +85,13 @@ func newReportArtifactCmd(out io.Writer) *cobra.Command {
ci := WhichCI()
cmd.Flags().StringVarP(&o.payload.Fingerprint, "fingerprint", "F", "", fingerprintFlag)
cmd.Flags().StringVarP(&o.flowName, "flow", "f", "", flowNameFlag)
cmd.Flags().StringVarP(&o.payload.GitCommit, "git-commit", "g", DefaultValue(ci, "git-commit"), gitCommitFlag)
cmd.Flags().StringVarP(&o.gitReference, "git-commit", "g", DefaultValue(ci, "git-commit"), gitCommitFlag)
cmd.Flags().StringVarP(&o.payload.BuildUrl, "build-url", "b", DefaultValue(ci, "build-url"), buildUrlFlag)
cmd.Flags().StringVarP(&o.payload.CommitUrl, "commit-url", "u", DefaultValue(ci, "commit-url"), commitUrlFlag)
cmd.Flags().StringVar(&o.srcRepoRoot, "repo-root", ".", repoRootFlag)
addFingerprintFlags(cmd, o.fingerprintOptions)
// cmd.Flags().StringSliceVarP(&o.fingerprintOptions.excludePaths, "exclude", "e", []string{}, excludePathsFlag)

addDryRunFlag(cmd)

err := RequireFlags(cmd, []string{"flow", "git-commit", "build-url", "commit-url"})
Expand Down Expand Up @@ -125,6 +128,13 @@ func (o *reportArtifactOptions) run(args []string) error {
return err
}

commitObject, err := gitView.GetCommitInfoFromCommitSHA(o.gitReference)
if err != nil {
return err
}

o.payload.GitCommit = commitObject.Sha1

o.payload.CommitsList, err = gitView.ChangeLog(o.payload.GitCommit, previousCommit, logger)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/kosli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ More details can be found here: https://aws.github.io/aws-sdk-go-v2/docs/configu
awsRegionFlag = "The AWS region."
bucketNameFlag = "The name of the S3 bucket."
pathsFlag = "The comma separated list of artifact directories."
excludePathsFlag = "[optional] The comma separated list of directories and files to exclude from fingerprinting."
excludePathsFlag = "[optional] The comma separated list of directories and files to exclude from fingerprinting. Only applicable for --artifact-type dir."
shortFlag = "[optional] Print only the Kosli CLI version number."
longFlag = "[optional] Print detailed output."
reverseFlag = "[defaulted] Reverse the order of output list."
Expand Down
12 changes: 10 additions & 2 deletions cmd/kosli/snapshotServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ func newSnapshotServerCmd(out io.Writer) *cobra.Command {
}

cmd.Flags().StringSliceVarP(&o.paths, "paths", "p", []string{}, pathsFlag)
cmd.Flags().StringSliceVarP(&o.excludePaths, "exclude", "e", []string{}, excludePathsFlag)
cmd.Flags().StringSliceVarP(&o.excludePaths, "exclude", "x", []string{}, excludePathsFlag)
cmd.Flags().StringSliceVarP(&o.excludePaths, "e", "e", []string{}, excludePathsFlag)
addDryRunFlag(cmd)

err := RequireFlags(cmd, []string{"paths"})
err := DeprecateFlags(cmd, map[string]string{
"e": "use -x instead",
})
if err != nil {
logger.Error("failed to configure deprecated flags: %v", err)
}

err = RequireFlags(cmd, []string{"paths"})
if err != nil {
logger.Error("failed to configure required flags: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/kosli/testHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ func CreateWorkflowEvidence(auditTrailName, externalId string, t *testing.T) {
func CreateArtifact(flowName, artifactFingerprint, artifactName string, t *testing.T) {
t.Helper()
o := &reportArtifactOptions{
srcRepoRoot: "../..",
flowName: flowName,
srcRepoRoot: "../..",
flowName: flowName,
gitReference: "0fc1ba9876f91b215679f3649b8668085d820ab5",
payload: ArtifactPayload{
Fingerprint: artifactFingerprint,
GitCommit: "0fc1ba9876f91b215679f3649b8668085d820ab5",
Expand Down
1 change: 1 addition & 0 deletions cmd/kosli/testdata/folder1/folder2/hello2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello2
1 change: 1 addition & 0 deletions cmd/kosli/testdata/folder1/folder2/hello3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello3
1 change: 1 addition & 0 deletions cmd/kosli/testdata/output/docs/artifact.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ artifact {IMAGE-NAME | FILE-PATH | DIR-PATH} [flags]
| -b, --build-url string | The url of CI pipeline that built the artifact. (defaulted in some CIs: https://docs.kosli.com/ci-defaults ). |
| -u, --commit-url string | The url for the git commit that created the artifact. (defaulted in some CIs: https://docs.kosli.com/ci-defaults ). |
| -D, --dry-run | [optional] Run in dry-run mode. When enabled, no data is sent to Kosli and the CLI exits with 0 exit code regardless of any errors. |
| -x, --exclude strings | [optional] The comma separated list of directories and files to exclude from fingerprinting. Only applicable for --artifact-type dir. |
| -F, --fingerprint string | [conditional] The SHA256 fingerprint of the artifact. Only required if you don't specify '--artifact-type'. |
| -f, --flow string | The Kosli flow name. |
| -g, --git-commit string | The git commit from which the artifact was created. (defaulted in some CIs: https://docs.kosli.com/ci-defaults ). |
Expand Down
4 changes: 2 additions & 2 deletions docs.kosli.com/content/helm/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter
| kosliApiToken.secretKey | string | `""` | the name of the key in the secret data which contains the kosli API token |
| kosliApiToken.secretName | string | `""` | the name of the secret containing the kosli API token |
| nameOverride | string | `""` | overrides the name used for the created k8s resources. If `fullnameOverride` is provided, it has higher precedence than this one |
| podAnnotations | object | `{}` | |
| podAnnotations | object | `{}` | any custom annotations to be added to the cronjob |
| reporterConfig.dryRun | bool | `false` | whether the dry run mode is enabled or not. In dry run mode, the reporter logs the reports to stdout and does not send them to kosli. |
| reporterConfig.kosliEnvironmentName | string | `""` | the name of kosli environment that the k8s cluster/namespace correlates to |
| reporterConfig.kosliOrg | string | `""` | the name of the kosli org |
Expand All @@ -74,5 +74,5 @@ helm upgrade [RELEASE-NAME] kosli/k8s-reporter
| serviceAccount.name | string | `""` | the name of the service account to use. If not set and create is true, a name is generated using the fullname template |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0)
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)

0 comments on commit cff82cd

Please sign in to comment.