mirror of https://github.com/helm/helm
commit
d43aaa4b15
@ -1,20 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Copyright The Helm Authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
curl -sSL https://github.com/golangci/golangci-lint/releases/download/v$GOLANGCI_LINT_VERSION/golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64.tar.gz | tar xz
|
|
||||||
sudo mv golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64/golangci-lint /usr/local/bin/golangci-lint
|
|
||||||
rm -rf golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64
|
|
@ -1,49 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Copyright The Helm Authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Skip on pull request builds
|
|
||||||
if [[ -n "${CIRCLE_PR_NUMBER:-}" ]]; then
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
: ${AZURE_STORAGE_CONNECTION_STRING:?"AZURE_STORAGE_CONNECTION_STRING environment variable is not set"}
|
|
||||||
: ${AZURE_STORAGE_CONTAINER_NAME:?"AZURE_STORAGE_CONTAINER_NAME environment variable is not set"}
|
|
||||||
|
|
||||||
VERSION=
|
|
||||||
if [[ -n "${CIRCLE_TAG:-}" ]]; then
|
|
||||||
VERSION="${CIRCLE_TAG}"
|
|
||||||
elif [[ "${CIRCLE_BRANCH:-}" == "master" ]]; then
|
|
||||||
VERSION="canary"
|
|
||||||
else
|
|
||||||
echo "Skipping deploy step; this is neither a releasable branch or a tag"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Installing Azure CLI"
|
|
||||||
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ stretch main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
|
|
||||||
curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add
|
|
||||||
sudo apt install apt-transport-https
|
|
||||||
sudo apt update
|
|
||||||
sudo apt install azure-cli
|
|
||||||
|
|
||||||
|
|
||||||
echo "Building helm binaries"
|
|
||||||
make build-cross
|
|
||||||
make dist checksum VERSION="${VERSION}"
|
|
||||||
|
|
||||||
echo "Pushing binaries to Azure"
|
|
||||||
az storage blob upload-batch -s _dist/ -d "$AZURE_STORAGE_CONTAINER_NAME" --pattern 'helm-*' --connection-string "$AZURE_STORAGE_CONNECTION_STRING"
|
|
@ -0,0 +1,11 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "gomod"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
@ -0,0 +1,36 @@
|
|||||||
|
name: build-test
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
- 'release-**'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # pin@v3.5.3
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # pin@4.1.0
|
||||||
|
with:
|
||||||
|
go-version: '1.20'
|
||||||
|
- name: Install golangci-lint
|
||||||
|
run: |
|
||||||
|
curl -sSLO https://github.com/golangci/golangci-lint/releases/download/v$GOLANGCI_LINT_VERSION/golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64.tar.gz
|
||||||
|
shasum -a 256 golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64.tar.gz | grep "^$GOLANGCI_LINT_SHA256 " > /dev/null
|
||||||
|
tar -xf golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64.tar.gz
|
||||||
|
sudo mv golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64/golangci-lint /usr/local/bin/golangci-lint
|
||||||
|
rm -rf golangci-lint-$GOLANGCI_LINT_VERSION-linux-amd64*
|
||||||
|
env:
|
||||||
|
GOLANGCI_LINT_VERSION: '1.51.2'
|
||||||
|
GOLANGCI_LINT_SHA256: '4de479eb9d9bc29da51aec1834e7c255b333723d38dbd56781c68e5dddc6a90b'
|
||||||
|
- name: Test style
|
||||||
|
run: make test-style
|
||||||
|
- name: Run unit tests
|
||||||
|
run: make test-coverage
|
||||||
|
- name: Test build
|
||||||
|
run: make build
|
@ -0,0 +1,75 @@
|
|||||||
|
name: release
|
||||||
|
on:
|
||||||
|
create:
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
# Note the only differences between release and canary-release jobs are:
|
||||||
|
# - only canary passes --overwrite flag
|
||||||
|
# - the VERSION make variable passed to 'make dist checksum' is expected to
|
||||||
|
# be "canary" if the job is triggered by a push to "main" branch. If the
|
||||||
|
# job is triggered by a tag push, VERSION should be the tag ref.
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # pin@v3.5.3
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # pin@4.1.0
|
||||||
|
with:
|
||||||
|
go-version: '1.20'
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: make test-coverage
|
||||||
|
|
||||||
|
- name: Build Helm Binaries
|
||||||
|
run: |
|
||||||
|
make build-cross
|
||||||
|
make dist checksum VERSION="${{ github.ref_name }}"
|
||||||
|
|
||||||
|
- name: Upload Binaries
|
||||||
|
uses: bacongobbler/azure-blob-storage-upload@50f7d898b7697e864130ea04c303ca38b5751c50 # pin@3.0.0
|
||||||
|
env:
|
||||||
|
AZURE_STORAGE_CONNECTION_STRING: "${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"
|
||||||
|
AZURE_STORAGE_CONTAINER_NAME: "${{ secrets.AZURE_STORAGE_CONTAINER_NAME }}"
|
||||||
|
with:
|
||||||
|
source_dir: _dist
|
||||||
|
container_name: ${{ secrets.AZURE_STORAGE_CONTAINER_NAME }}
|
||||||
|
connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
|
||||||
|
extra_args: '--pattern helm-*'
|
||||||
|
|
||||||
|
canary-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # pin@v3.5.3
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # pin@4.1.0
|
||||||
|
with:
|
||||||
|
go-version: '1.20'
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: make test-coverage
|
||||||
|
|
||||||
|
- name: Build Helm Binaries
|
||||||
|
run: |
|
||||||
|
make build-cross
|
||||||
|
make dist checksum VERSION="canary"
|
||||||
|
|
||||||
|
- name: Upload Binaries
|
||||||
|
uses: bacongobbler/azure-blob-storage-upload@50f7d898b7697e864130ea04c303ca38b5751c50 # pin@3.0.0
|
||||||
|
with:
|
||||||
|
source_dir: _dist
|
||||||
|
container_name: ${{ secrets.AZURE_STORAGE_CONTAINER_NAME }}
|
||||||
|
connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
|
||||||
|
extra_args: '--pattern helm-*'
|
||||||
|
# WARNING: this will overwrite existing blobs in your blob storage
|
||||||
|
overwrite: 'true'
|
@ -0,0 +1,16 @@
|
|||||||
|
name: "Close stale issues"
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 0 * * *"
|
||||||
|
jobs:
|
||||||
|
stale:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v3.0.14
|
||||||
|
with:
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
stale-issue-message: 'This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.'
|
||||||
|
exempt-issue-labels: 'keep open,v4.x,in progress'
|
||||||
|
days-before-stale: 90
|
||||||
|
days-before-close: 30
|
||||||
|
operations-per-run: 100
|
@ -1,21 +1,28 @@
|
|||||||
maintainers:
|
maintainers:
|
||||||
- adamreese
|
|
||||||
- bacongobbler
|
|
||||||
- fibonacci1729
|
|
||||||
- hickeyma
|
- hickeyma
|
||||||
|
- joejulian
|
||||||
- jdolitsky
|
- jdolitsky
|
||||||
- marckhouzam
|
- marckhouzam
|
||||||
- mattfarina
|
- mattfarina
|
||||||
- prydonius
|
- sabre1041
|
||||||
- SlickNik
|
- scottrigby
|
||||||
- technosophos
|
- technosophos
|
||||||
- thomastaylor312
|
triage:
|
||||||
- viglesiasce
|
- yxxhero
|
||||||
|
- zonggen
|
||||||
|
- gjenkins8
|
||||||
emeritus:
|
emeritus:
|
||||||
|
- adamreese
|
||||||
|
- bacongobbler
|
||||||
|
- fibonacci1729
|
||||||
- jascott1
|
- jascott1
|
||||||
- michelleN
|
- michelleN
|
||||||
- migmartri
|
- migmartri
|
||||||
- nebril
|
- nebril
|
||||||
|
- prydonius
|
||||||
|
- rimusz
|
||||||
- seh
|
- seh
|
||||||
|
- SlickNik
|
||||||
|
- thomastaylor312
|
||||||
- vaikas-google
|
- vaikas-google
|
||||||
- rimusz
|
- viglesiasce
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
|
||||||
)
|
|
||||||
|
|
||||||
const chartHelp = `
|
|
||||||
This command consists of multiple subcommands to work with the chart cache.
|
|
||||||
|
|
||||||
The subcommands can be used to push, pull, tag, list, or remove Helm charts.
|
|
||||||
`
|
|
||||||
|
|
||||||
func newChartCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|
||||||
cmd := &cobra.Command{
|
|
||||||
Use: "chart",
|
|
||||||
Short: "push, pull, tag, or remove Helm charts",
|
|
||||||
Long: chartHelp,
|
|
||||||
Hidden: !FeatureGateOCI.IsEnabled(),
|
|
||||||
PersistentPreRunE: checkOCIFeatureGate(),
|
|
||||||
}
|
|
||||||
cmd.AddCommand(
|
|
||||||
newChartListCmd(cfg, out),
|
|
||||||
newChartExportCmd(cfg, out),
|
|
||||||
newChartPullCmd(cfg, out),
|
|
||||||
newChartPushCmd(cfg, out),
|
|
||||||
newChartRemoveCmd(cfg, out),
|
|
||||||
newChartSaveCmd(cfg, out),
|
|
||||||
)
|
|
||||||
return cmd
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/v3/cmd/helm/require"
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
|
||||||
)
|
|
||||||
|
|
||||||
const chartExportDesc = `
|
|
||||||
Export a chart stored in local registry cache.
|
|
||||||
|
|
||||||
This will create a new directory with the name of
|
|
||||||
the chart, in a format that developers can modify
|
|
||||||
and check into source control if desired.
|
|
||||||
`
|
|
||||||
|
|
||||||
func newChartExportCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|
||||||
client := action.NewChartExport(cfg)
|
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
|
||||||
Use: "export [ref]",
|
|
||||||
Short: "export a chart to directory",
|
|
||||||
Long: chartExportDesc,
|
|
||||||
Args: require.MinimumNArgs(1),
|
|
||||||
Hidden: !FeatureGateOCI.IsEnabled(),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
ref := args[0]
|
|
||||||
return client.Run(out, ref)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
f := cmd.Flags()
|
|
||||||
f.StringVarP(&client.Destination, "destination", "d", ".", "location to write the chart.")
|
|
||||||
|
|
||||||
return cmd
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
|
||||||
)
|
|
||||||
|
|
||||||
const chartListDesc = `
|
|
||||||
List all charts in the local registry cache.
|
|
||||||
|
|
||||||
Charts are sorted by ref name, alphabetically.
|
|
||||||
`
|
|
||||||
|
|
||||||
func newChartListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|
||||||
return &cobra.Command{
|
|
||||||
Use: "list",
|
|
||||||
Aliases: []string{"ls"},
|
|
||||||
Short: "list all saved charts",
|
|
||||||
Long: chartListDesc,
|
|
||||||
Hidden: !FeatureGateOCI.IsEnabled(),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
return action.NewChartList(cfg).Run(out)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/v3/cmd/helm/require"
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
|
||||||
)
|
|
||||||
|
|
||||||
const chartPullDesc = `
|
|
||||||
Download a chart from a remote registry.
|
|
||||||
|
|
||||||
This will store the chart in the local registry cache to be used later.
|
|
||||||
`
|
|
||||||
|
|
||||||
func newChartPullCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|
||||||
return &cobra.Command{
|
|
||||||
Use: "pull [ref]",
|
|
||||||
Short: "pull a chart from remote",
|
|
||||||
Long: chartPullDesc,
|
|
||||||
Args: require.MinimumNArgs(1),
|
|
||||||
Hidden: !FeatureGateOCI.IsEnabled(),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
ref := args[0]
|
|
||||||
return action.NewChartPull(cfg).Run(out, ref)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/v3/cmd/helm/require"
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
|
||||||
)
|
|
||||||
|
|
||||||
const chartPushDesc = `
|
|
||||||
Upload a chart to a remote registry.
|
|
||||||
|
|
||||||
Note: the ref must already exist in the local registry cache.
|
|
||||||
|
|
||||||
Must first run "helm chart save" or "helm chart pull".
|
|
||||||
`
|
|
||||||
|
|
||||||
func newChartPushCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|
||||||
return &cobra.Command{
|
|
||||||
Use: "push [ref]",
|
|
||||||
Short: "push a chart to remote",
|
|
||||||
Long: chartPushDesc,
|
|
||||||
Args: require.MinimumNArgs(1),
|
|
||||||
Hidden: !FeatureGateOCI.IsEnabled(),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
ref := args[0]
|
|
||||||
return action.NewChartPush(cfg).Run(out, ref)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/v3/cmd/helm/require"
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
|
||||||
)
|
|
||||||
|
|
||||||
const chartRemoveDesc = `
|
|
||||||
Remove a chart from the local registry cache.
|
|
||||||
|
|
||||||
Note: the chart content will still exist in the cache,
|
|
||||||
but it will no longer appear in "helm chart list".
|
|
||||||
|
|
||||||
To remove all unlinked content, please run "helm chart prune". (TODO)
|
|
||||||
`
|
|
||||||
|
|
||||||
func newChartRemoveCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|
||||||
return &cobra.Command{
|
|
||||||
Use: "remove [ref]",
|
|
||||||
Aliases: []string{"rm"},
|
|
||||||
Short: "remove a chart",
|
|
||||||
Long: chartRemoveDesc,
|
|
||||||
Args: require.MinimumNArgs(1),
|
|
||||||
Hidden: !FeatureGateOCI.IsEnabled(),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
ref := args[0]
|
|
||||||
return action.NewChartRemove(cfg).Run(out, ref)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/v3/cmd/helm/require"
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
|
||||||
"helm.sh/helm/v3/pkg/chart/loader"
|
|
||||||
)
|
|
||||||
|
|
||||||
const chartSaveDesc = `
|
|
||||||
Store a copy of chart in local registry cache.
|
|
||||||
|
|
||||||
Note: modifying the chart after this operation will
|
|
||||||
not change the item as it exists in the cache.
|
|
||||||
`
|
|
||||||
|
|
||||||
func newChartSaveCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|
||||||
return &cobra.Command{
|
|
||||||
Use: "save [path] [ref]",
|
|
||||||
Short: "save a chart directory",
|
|
||||||
Long: chartSaveDesc,
|
|
||||||
Args: require.MinimumNArgs(2),
|
|
||||||
Hidden: !FeatureGateOCI.IsEnabled(),
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
path := args[0]
|
|
||||||
ref := args[1]
|
|
||||||
|
|
||||||
path, err := filepath.Abs(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ch, err := loader.Load(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return action.NewChartSave(cfg).Run(out, ch, ref)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"helm.sh/helm/v3/pkg/chart"
|
||||||
|
"helm.sh/helm/v3/pkg/release"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check if file completion should be performed according to parameter 'shouldBePerformed'
|
||||||
|
func checkFileCompletion(t *testing.T, cmdName string, shouldBePerformed bool) {
|
||||||
|
storage := storageFixture()
|
||||||
|
storage.Create(&release.Release{
|
||||||
|
Name: "myrelease",
|
||||||
|
Info: &release.Info{Status: release.StatusDeployed},
|
||||||
|
Chart: &chart.Chart{
|
||||||
|
Metadata: &chart.Metadata{
|
||||||
|
Name: "Myrelease-Chart",
|
||||||
|
Version: "1.2.3",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Version: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
testcmd := fmt.Sprintf("__complete %s ''", cmdName)
|
||||||
|
_, out, err := executeActionCommandC(storage, testcmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error, %s", err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, "ShellCompDirectiveNoFileComp") != shouldBePerformed {
|
||||||
|
if shouldBePerformed {
|
||||||
|
t.Errorf("Unexpected directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
t.Errorf("Did not receive directive ShellCompDirectiveNoFileComp when completing '%s'", cmdName)
|
||||||
|
}
|
||||||
|
t.Log(out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompletionFileCompletion(t *testing.T) {
|
||||||
|
checkFileCompletion(t, "completion", false)
|
||||||
|
checkFileCompletion(t, "completion bash", false)
|
||||||
|
checkFileCompletion(t, "completion zsh", false)
|
||||||
|
checkFileCompletion(t, "completion fish", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkReleaseCompletion(t *testing.T, cmdName string, multiReleasesAllowed bool) {
|
||||||
|
multiReleaseTestGolden := "output/empty_nofile_comp.txt"
|
||||||
|
if multiReleasesAllowed {
|
||||||
|
multiReleaseTestGolden = "output/release_list_repeat_comp.txt"
|
||||||
|
}
|
||||||
|
tests := []cmdTestCase{{
|
||||||
|
name: "completion for uninstall",
|
||||||
|
cmd: fmt.Sprintf("__complete %s ''", cmdName),
|
||||||
|
golden: "output/release_list_comp.txt",
|
||||||
|
rels: []*release.Release{
|
||||||
|
release.Mock(&release.MockReleaseOptions{Name: "athos"}),
|
||||||
|
release.Mock(&release.MockReleaseOptions{Name: "porthos"}),
|
||||||
|
release.Mock(&release.MockReleaseOptions{Name: "aramis"}),
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
name: "completion for uninstall repetition",
|
||||||
|
cmd: fmt.Sprintf("__complete %s porthos ''", cmdName),
|
||||||
|
golden: multiReleaseTestGolden,
|
||||||
|
rels: []*release.Release{
|
||||||
|
release.Mock(&release.MockReleaseOptions{Name: "athos"}),
|
||||||
|
release.Mock(&release.MockReleaseOptions{Name: "porthos"}),
|
||||||
|
release.Mock(&release.MockReleaseOptions{Name: "aramis"}),
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
for _, test := range tests {
|
||||||
|
runTestCmd(t, []cmdTestCase{test})
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDocsTypeFlagCompletion(t *testing.T) {
|
||||||
|
tests := []cmdTestCase{{
|
||||||
|
name: "completion for docs --type",
|
||||||
|
cmd: "__complete docs --type ''",
|
||||||
|
golden: "output/docs-type-comp.txt",
|
||||||
|
}, {
|
||||||
|
name: "completion for docs --type, no filter",
|
||||||
|
cmd: "__complete docs --type mar",
|
||||||
|
golden: "output/docs-type-comp.txt",
|
||||||
|
}}
|
||||||
|
runTestCmd(t, tests)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDocsFileCompletion(t *testing.T) {
|
||||||
|
checkFileCompletion(t, "docs", false)
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"helm.sh/helm/v3/cmd/helm/require"
|
||||||
|
"helm.sh/helm/v3/pkg/action"
|
||||||
|
"helm.sh/helm/v3/pkg/pusher"
|
||||||
|
)
|
||||||
|
|
||||||
|
const pushDesc = `
|
||||||
|
Upload a chart to a registry.
|
||||||
|
|
||||||
|
If the chart has an associated provenance file,
|
||||||
|
it will also be uploaded.
|
||||||
|
`
|
||||||
|
|
||||||
|
type registryPushOptions struct {
|
||||||
|
certFile string
|
||||||
|
keyFile string
|
||||||
|
caFile string
|
||||||
|
insecureSkipTLSverify bool
|
||||||
|
plainHTTP bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPushCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
||||||
|
o := ®istryPushOptions{}
|
||||||
|
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "push [chart] [remote]",
|
||||||
|
Short: "push a chart to remote",
|
||||||
|
Long: pushDesc,
|
||||||
|
Args: require.MinimumNArgs(2),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
// Do file completion for the chart file to push
|
||||||
|
return nil, cobra.ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
if len(args) == 1 {
|
||||||
|
providers := []pusher.Provider(pusher.All(settings))
|
||||||
|
var comps []string
|
||||||
|
for _, p := range providers {
|
||||||
|
for _, scheme := range p.Schemes {
|
||||||
|
comps = append(comps, fmt.Sprintf("%s://", scheme))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return comps, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace
|
||||||
|
}
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
registryClient, err := newRegistryClient(o.certFile, o.keyFile, o.caFile, o.insecureSkipTLSverify, o.plainHTTP)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("missing registry client: %w", err)
|
||||||
|
}
|
||||||
|
cfg.RegistryClient = registryClient
|
||||||
|
chartRef := args[0]
|
||||||
|
remote := args[1]
|
||||||
|
client := action.NewPushWithOpts(action.WithPushConfig(cfg),
|
||||||
|
action.WithTLSClientConfig(o.certFile, o.keyFile, o.caFile),
|
||||||
|
action.WithInsecureSkipTLSVerify(o.insecureSkipTLSverify),
|
||||||
|
action.WithPlainHTTP(o.plainHTTP),
|
||||||
|
action.WithPushOptWriter(out))
|
||||||
|
client.Settings = settings
|
||||||
|
output, err := client.Run(chartRef, remote)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprint(out, output)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
f := cmd.Flags()
|
||||||
|
f.StringVar(&o.certFile, "cert-file", "", "identify registry client using this SSL certificate file")
|
||||||
|
f.StringVar(&o.keyFile, "key-file", "", "identify registry client using this SSL key file")
|
||||||
|
f.StringVar(&o.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
|
||||||
|
f.BoolVar(&o.insecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart upload")
|
||||||
|
f.BoolVar(&o.plainHTTP, "plain-http", false, "use insecure HTTP connections for the chart upload")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPushFileCompletion(t *testing.T) {
|
||||||
|
checkFileCompletion(t, "push", true)
|
||||||
|
checkFileCompletion(t, "push package.tgz", false)
|
||||||
|
checkFileCompletion(t, "push package.tgz oci://localhost:5000", false)
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRegistryLogoutFileCompletion(t *testing.T) {
|
||||||
|
checkFileCompletion(t, "registry logout", false)
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRepoFileCompletion(t *testing.T) {
|
||||||
|
checkFileCompletion(t, "repo", false)
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkPerms() {
|
||||||
|
// This function MUST NOT FAIL, as it is just a check for a common permissions problem.
|
||||||
|
// If for some reason the function hits a stopping condition, it may panic. But only if
|
||||||
|
// we can be sure that it is panicking because Helm cannot proceed.
|
||||||
|
|
||||||
|
kc := settings.KubeConfig
|
||||||
|
if kc == "" {
|
||||||
|
kc = os.Getenv("KUBECONFIG")
|
||||||
|
}
|
||||||
|
if kc == "" {
|
||||||
|
u, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
// No idea where to find KubeConfig, so return silently. Many helm commands
|
||||||
|
// can proceed happily without a KUBECONFIG, so this is not a fatal error.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
kc = filepath.Join(u.HomeDir, ".kube", "config")
|
||||||
|
}
|
||||||
|
fi, err := os.Stat(kc)
|
||||||
|
if err != nil {
|
||||||
|
// DO NOT error if no KubeConfig is found. Not all commands require one.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
perm := fi.Mode().Perm()
|
||||||
|
if perm&0040 > 0 {
|
||||||
|
warning("Kubernetes configuration file is group-readable. This is insecure. Location: %s", kc)
|
||||||
|
}
|
||||||
|
if perm&0004 > 0 {
|
||||||
|
warning("Kubernetes configuration file is world-readable. This is insecure. Location: %s", kc)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkPermsStderr() (string, error) {
|
||||||
|
r, w, err := os.Pipe()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
stderr := os.Stderr
|
||||||
|
os.Stderr = w
|
||||||
|
defer func() {
|
||||||
|
os.Stderr = stderr
|
||||||
|
}()
|
||||||
|
|
||||||
|
checkPerms()
|
||||||
|
w.Close()
|
||||||
|
|
||||||
|
var text bytes.Buffer
|
||||||
|
io.Copy(&text, r)
|
||||||
|
return text.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckPerms(t *testing.T) {
|
||||||
|
tdir := t.TempDir()
|
||||||
|
tfile := filepath.Join(tdir, "testconfig")
|
||||||
|
fh, err := os.OpenFile(tfile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0440)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to create temp file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tconfig := settings.KubeConfig
|
||||||
|
settings.KubeConfig = tfile
|
||||||
|
defer func() { settings.KubeConfig = tconfig }()
|
||||||
|
|
||||||
|
text, err := checkPermsStderr()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not read from stderr: %s", err)
|
||||||
|
}
|
||||||
|
expectPrefix := "WARNING: Kubernetes configuration file is group-readable. This is insecure. Location:"
|
||||||
|
if !strings.HasPrefix(text, expectPrefix) {
|
||||||
|
t.Errorf("Expected to get a warning for group perms. Got %q", text)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := fh.Chmod(0404); err != nil {
|
||||||
|
t.Errorf("Could not change mode on file: %s", err)
|
||||||
|
}
|
||||||
|
text, err = checkPermsStderr()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not read from stderr: %s", err)
|
||||||
|
}
|
||||||
|
expectPrefix = "WARNING: Kubernetes configuration file is world-readable. This is insecure. Location:"
|
||||||
|
if !strings.HasPrefix(text, expectPrefix) {
|
||||||
|
t.Errorf("Expected to get a warning for world perms. Got %q", text)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func checkPerms() {
|
||||||
|
// Not yet implemented on Windows. If you know how to do a comprehensive perms
|
||||||
|
// check on Windows, contributions welcomed!
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue