Unverified Commit 259aa361 authored by Nicholas Seemiller's avatar Nicholas Seemiller Committed by GitHub
Browse files

Add local-path-storage 0.0.22 (#3825)

parent a539f77b
Showing with 1784 additions and 0 deletions
+1784 -0
FROM golang:1.16 as builder
RUN go get github.com/rancher/local-path-provisioner@v0.0.22
FROM gcr.io/distroless/base
COPY --from=builder /go/bin/local-path-provisioner /bin/local-path-provisioner
ENTRYPOINT ["local-path-provisioner"]
# Local Path Storage - v0.0.20
This package provides local path node storage and primarily supports RWO AccessMode.
It utilizes the Kubernetes [Local Persistent Volume feature](https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/)
and in Tanzu Community Edition, it is primarily intended for use with Docker, although it will work with any infrastructure provider
or package where persistent storage is needed.
This package also provides a `StorageClass`.
If there is no `StorageClass` already installed on the cluster,
then the `StorageClass` provided in this package will automatically be made the default.
Otherwise, the [`storageclass.kubernetes.io/is-default-class` may need to be modified.](https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class/)
## Limitations
The local-path-storage binds to a single host node
and is not intended to dynamically change hosts.
Therefore, a PVC can _only_ be used by the node that creates it.
This can lead to unintended data loss when scaling or when pods roll from one node to another.
Further, it can make scheduling difficult since applications are "tied" to the node that created it's PV.
Further, local-path-storage does _not_ enforce capacity limitations
and may, possibly overwhelm the local node's disc capacity.
See the [local-path-storage GitHub](https://github.com/rancher/local-path-provisioner)
for further documentation and configuration options.
## Configuration
| Value | Required/Optional | Description |
|-------------------------------------------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `namespace` | Required | The namespace to deploy the local-path-storage pods |
*Note:* The local path storage provides a config map that may be modified _after_ installation.
This includes a `config.json` that can be used to further configure the storage provider.
Additionally, `setup` and `teardown` scripts are defined in the config map and are used in the lifecycle of persistent volumes.
The local-path-storage pods will dynamically reload the config map upon configuration without need to reapply the deployment.
## Usage Examples
A StorageClass is required in order to use PVCs and store data (which is necessary for services
like Prometheus). The local-path-storage provider enables local Docker clusters to store data locally.
Using a local PVC with Docker lets a developer work quickly on their own workstation with Docker.
A local storage provider may also be used in special cases for caching, sharding data in distributed datastores,
and other node failure tolerant storage models.
Note that local storage providers are generally not suitable for most production use cases.
apiVersion: imgpkg.carvel.dev/v1alpha1
kind: Bundle
metadata:
name: local-path-storage
authors:
- name: John McBride
- name: Nicholas Seemiller
websites:
- url: github.com/rancher/local-path-provisioner
- url: github.com/vmware-tanzu/tce
---
apiVersion: imgpkg.carvel.dev/v1alpha1
images:
- annotations:
kbld.carvel.dev/id: busybox
kbld.carvel.dev/origins: |
- resolved:
tag: latest
url: busybox
image: index.docker.io/library/busybox@sha256:caa382c432891547782ce7140fb3b7304613d3b0438834dce1cad68896ab110a
- annotations:
kbld.carvel.dev/id: rancher/local-path-provisioner:v0.0.22
kbld.carvel.dev/origins: |
- resolved:
tag: v0.0.22
url: projects.registry.vmware.com/tce/local-path-provisioner:v0.0.22
image: projects.registry.vmware.com/tce/local-path-provisioner@sha256:a7ac6e6b982c867d8ff05a464448e62f3af29868a405fde1d38a1ca950c4f998
kind: ImagesLock
#@ load("@ytt:data", "data")
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.subset({"kind":"Namespace", "metadata": {"name": "local-path-storage"}})
---
metadata:
name: #@ data.values.namespace
#@overlay/match by=overlay.subset({"metadata":{"namespace": "local-path-storage"}}), expects=3
---
metadata:
namespace: #@ data.values.namespace
#@overlay/match by=overlay.subset({"kind":"ClusterRoleBinding"}), expects=1
---
subjects:
#@overlay/match by=overlay.subset({"namespace": "local-path-storage"})
- kind: ServiceAccount
namespace: #@ data.values.namespace
#@ load("@ytt:data", "data")
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.subset({"kind": "StorageClass"})
#@overlay/match-child-defaults missing_ok=True
---
metadata:
annotations:
storageclass.kubernetes.io/is-default-class: "true"
apiVersion: v1
kind: Namespace
metadata:
name: local-path-storage
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: local-path-provisioner-service-account
namespace: local-path-storage
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: local-path-provisioner-role
rules:
- apiGroups: [ "" ]
resources: [ "nodes", "persistentvolumeclaims", "configmaps" ]
verbs: [ "get", "list", "watch" ]
- apiGroups: [ "" ]
resources: [ "endpoints", "persistentvolumes", "pods" ]
verbs: [ "*" ]
- apiGroups: [ "" ]
resources: [ "events" ]
verbs: [ "create", "patch" ]
- apiGroups: [ "storage.k8s.io" ]
resources: [ "storageclasses" ]
verbs: [ "get", "list", "watch" ]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: local-path-provisioner-bind
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: local-path-provisioner-role
subjects:
- kind: ServiceAccount
name: local-path-provisioner-service-account
namespace: local-path-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-path-provisioner
namespace: local-path-storage
spec:
replicas: 1
selector:
matchLabels:
app: local-path-provisioner
template:
metadata:
labels:
app: local-path-provisioner
spec:
serviceAccountName: local-path-provisioner-service-account
containers:
- name: local-path-provisioner
image: rancher/local-path-provisioner:v0.0.22
imagePullPolicy: IfNotPresent
command:
- local-path-provisioner
- --debug
- start
- --config
- /etc/config/config.json
volumeMounts:
- name: config-volume
mountPath: /etc/config/
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumes:
- name: config-volume
configMap:
name: local-path-config
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-path
provisioner: rancher.io/local-path
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
---
kind: ConfigMap
apiVersion: v1
metadata:
name: local-path-config
namespace: local-path-storage
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/opt/local-path-provisioner"]
}
]
}
setup: |-
#!/bin/sh
set -eu
mkdir -m 0777 -p "$VOL_DIR"
teardown: |-
#!/bin/sh
set -eu
rm -rf "$VOL_DIR"
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: busybox
imagePullPolicy: IfNotPresent
#@data/values
---
namespace: local-path-storage
---
apiVersion: kbld.k14s.io/v1alpha1
kind: Config
minimumRequiredVersion: 0.15.0
overrides:
- image: rancher/local-path-provisioner:v0.0.22
newImage: projects.registry.vmware.com/tce/local-path-provisioner:v0.0.22
searchRules:
- keyMatcher:
name: helperPod.yaml
updateStrategy:
yaml:
searchRules:
- keyMatcher:
name: image
apiVersion: vendir.k14s.io/v1alpha1
directories:
- contents:
- git:
commitTitle: Update README.md...
sha: 5673be1cb492321108b7fbc68fad63a03ceeacc4
tags:
- v0.0.22
path: local-path-storage.yaml
path: config/upstream
kind: LockConfig
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
minimumRequiredVersion: 0.0.20
directories:
- path: config/upstream
contents:
- path: local-path-storage.yaml
git:
url: https://github.com/rancher/local-path-provisioner
ref: v0.0.22
newRootPath: deploy/
includePaths:
- deploy/local-path-storage.yaml
apiVersion: data.packaging.carvel.dev/v1alpha1
kind: Package
metadata:
name: local-path-storage.community.tanzu.vmware.com.0.0.22
spec:
refName: local-path-storage.community.tanzu.vmware.com
version: 0.0.22
releasedAt: 2021-09-15T00:00:00Z
releaseNotes: "local-path-storage 0.0.22 https://github.com/rancher/local-path-provisioner/releases/tag/v0.0.22"
capacityRequirementsDescription: "Only suitable for local node storage. Does not provide distributed, reliable storage"
licenses:
- "Apache 2.0"
valuesSchema:
openAPIv3:
title: local-path-storage.community.tanzu.vmware.com.0.0.22 values schema
properties:
namespace:
type: string
description: The namespace in which to deploy the local-path-storage package
default: local-path-storage
template:
spec:
fetch:
- imgpkgBundle:
image: projects.registry.vmware.com/tce/local-path-storage@sha256:9c138c1e2bb54a2f9495b9ce3fc8cebba2afc46d0f296a93ff7ef9f7ae32373f
template:
- ytt:
paths:
- config/
- kbld:
paths:
- "-"
- .imgpkg/images.yml
deploy:
- kapp: {}
# Copyright 2021 VMware Tanzu Community Edition contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
.DEFAULT_GOAL:=help
help: ## Display this help message
# Inspired by Cluster-API Makefile
# Any target that has '## ' append to it will be included in the help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9A-Za-z_-]+:.*?##/ { printf " \033[36m%-45s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
lint: ## Run Go code linting
ifeq ($(origin GOLANGCI_LINT),undefined)
@echo "Error! GOLANGCI_LINT env var not set"
else
$(GOLANGCI_LINT) run -v --timeout=5m
endif
get-deps: ## Get all dependencies
go mod download
unit-test: ## Run unit testing suite
CGO_ENABLED=0 go run github.com/onsi/ginkgo/ginkgo -v unittest
e2e-test: ## Run e2e testing suite
CGO_ENABLED=0 go run github.com/onsi/ginkgo/ginkgo -v e2e
build: ## Build the executable
@echo "TODO: implement building"
# Tests
## End-to-End Tests
The end-to-end tests assume that a cluster is running and that the correct version of the package under test is available in a package repository that is already installed to the cluster.
To execute the end-to-end tests, run
```shell
make e2e-test
```
## Unit Tests
To execute the unit tests, run
```shell
make unit-test
```
// Copyright 2021 VMware Tanzu Community Edition contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// package e2e_test implements running the local-path-storage end-to-end tests
package e2e_test
import (
"encoding/json"
"fmt"
"math/rand"
"path/filepath"
"strings"
"testing"
"time"
"github.com/vmware-tanzu/community-edition/addons/packages/test/pkg/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func Test(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "local-path-storage Package E2E Test Suite")
}
const (
packagePollInterval = "10s"
packagePollTimeout = "20m"
)
var (
// packageInstallNamespace is the namespace where the package is installed
packageInstallNamespace string
// packageInstallName is the app name of the installed package
packageInstallName string
// installedPackages record the packages installed by the test
installedPackages []string
)
var _ = BeforeSuite(func() {
packageInstallNamespace = "default"
packageInstallName = "local-path-storage"
By("installing local-path-storage package")
packageName := utils.TanzuPackageName(packageInstallName)
version := findPackageAvailableVersion(packageName, "0.0.22")
valuesFilename := filepath.Join("fixtures", "local-path-storage-values.yaml")
installPackage(packageInstallName, packageName, version, valuesFilename)
By("validating local-path-storage package is reconciled")
utils.ValidatePackageInstallReady(packageInstallNamespace, packageInstallName)
})
var _ = AfterSuite(func() {
for _, installedPackage := range installedPackages {
By(fmt.Sprintf("cleaning up %s package", installedPackage))
_, err := utils.Tanzu(nil, "package", "installed", "delete", installedPackage,
"--poll-interval", packagePollInterval,
"--poll-timeout", packagePollTimeout,
"--namespace", packageInstallNamespace, "--yes")
Expect(err).NotTo(HaveOccurred())
}
By("validating the local-path-storage package install no longer exists")
utils.ValidatePackageInstallNotFound(packageInstallNamespace, packageInstallName)
})
func findPackageAvailableVersion(packageName string, versionSubstr string) string {
packageVersionJSON, err := utils.Tanzu(nil, "package", "available", "list", packageName, "-o", "json")
Expect(err).NotTo(HaveOccurred())
versions := []map[string]string{}
err = json.Unmarshal([]byte(packageVersionJSON), &versions)
Expect(err).NotTo(HaveOccurred())
Expect(len(versions)).To(BeNumerically(">", 0))
var matchedVersions []string
for _, v := range versions {
if versionSubstr == "" || strings.Contains(v["version"], versionSubstr) {
matchedVersions = append(matchedVersions, v["version"])
}
}
Expect(len(matchedVersions)).To(BeNumerically(">", 0), fmt.Sprintf("version contains %s for package %s not found", versionSubstr, packageName))
return matchedVersions[len(matchedVersions)-1]
}
func installPackage(name, packageName, version, valuesFilename string) {
installedPackages = append([]string{name}, installedPackages...)
args := []string{
"package", "install", name,
"--poll-interval", packagePollInterval,
"--poll-timeout", packagePollTimeout,
"--namespace", packageInstallNamespace,
"--package-name", packageName,
"--version", version,
}
if valuesFilename != "" {
args = append(args, "--values-file", valuesFilename)
}
_, err := utils.Tanzu(nil, args...)
Expect(err).NotTo(HaveOccurred())
}
// Copyright 2021 VMware Tanzu Community Edition contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package e2e_test
import (
"fmt"
"github.com/vmware-tanzu/community-edition/addons/packages/test/pkg/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("local-path-storage Package E2E Test", func() {
JustAfterEach(func() {
if CurrentGinkgoTestDescription().Failed {
fmt.Fprintf(GinkgoWriter, "\nCollecting diagnostic information just after test failure\n")
fmt.Fprintf(GinkgoWriter, "\nResources summary:\n")
utils.Kubectl(nil, "-n", packageInstallNamespace, "get", "all,packageinstalls,apps") // nolint:errcheck
fmt.Fprintf(GinkgoWriter, "\npackage install status:\n")
utils.Kubectl(nil, "-n", packageInstallNamespace, "get", "app", packageInstallName, "-o", "jsonpath={.status}") // nolint:errcheck
}
})
It("works", func() {
_, err := utils.Kubectl(nil, "get", "StorageClass", "local-path")
Expect(err).NotTo(HaveOccurred())
})
})
module github.com/vmware-tanzu/community-edition/addons/packages/harbor/test
go 1.17
require (
github.com/containerd/containerd v1.5.7
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.16.0
github.com/opencontainers/image-spec v1.0.1
github.com/vmware-tanzu/community-edition/addons/packages/test/pkg v0.0.0-00010101000000-000000000000
k8s.io/api v0.23.5
oras.land/oras-go v0.4.0
)
require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.11.13 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.5 // indirect
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
google.golang.org/grpc v1.33.2 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apimachinery v0.23.5 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)
replace github.com/vmware-tanzu/community-edition/addons/packages/test/pkg => ../../../test/pkg
This diff is collapsed.
// +build tools
package tools
import (
_ "github.com/onsi/ginkgo/ginkgo"
)
// This file imports packages that are used when running go generate, or used
// during the development process but not otherwise depended on by built code.
apiVersion: v1
kind: Namespace
metadata:
name: local-path-storage
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: local-path-provisioner-service-account
namespace: local-path-storage
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: local-path-provisioner-role
rules:
- apiGroups:
- ""
resources:
- nodes
- persistentvolumeclaims
- configmaps
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- endpoints
- persistentvolumes
- pods
verbs:
- '*'
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- storage.k8s.io
resources:
- storageclasses
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: local-path-provisioner-bind
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: local-path-provisioner-role
subjects:
- kind: ServiceAccount
name: local-path-provisioner-service-account
namespace: local-path-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-path-provisioner
namespace: local-path-storage
spec:
replicas: 1
selector:
matchLabels:
app: local-path-provisioner
template:
metadata:
labels:
app: local-path-provisioner
spec:
serviceAccountName: local-path-provisioner-service-account
containers:
- name: local-path-provisioner
image: rancher/local-path-provisioner:v0.0.22
imagePullPolicy: IfNotPresent
command:
- local-path-provisioner
- --debug
- start
- --config
- /etc/config/config.json
volumeMounts:
- name: config-volume
mountPath: /etc/config/
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumes:
- name: config-volume
configMap:
name: local-path-config
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-path
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: rancher.io/local-path
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
---
kind: ConfigMap
apiVersion: v1
metadata:
name: local-path-config
namespace: local-path-storage
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/opt/local-path-provisioner"]
}
]
}
setup: |-
#!/bin/sh
set -eu
mkdir -m 0777 -p "$VOL_DIR"
teardown: |-
#!/bin/sh
set -eu
rm -rf "$VOL_DIR"
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: busybox
imagePullPolicy: IfNotPresent
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment