Skip to content

Commit

Permalink
Merge branch 'master' into 2238-auto-eviction
Browse files Browse the repository at this point in the history
  • Loading branch information
innobead authored Nov 23, 2023
2 parents 8e2a3bd + b8abca1 commit 570380c
Show file tree
Hide file tree
Showing 60 changed files with 2,207 additions and 924 deletions.
1 change: 1 addition & 0 deletions controller/backing_image_data_source_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
podSpec.Annotations[nadAnnot] = types.CreateCniAnnotationFromSetting(storageNetwork)
}

types.AddGoCoverDirToPod(podSpec)
return podSpec, nil
}

Expand Down
2 changes: 2 additions & 0 deletions controller/backing_image_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ func (c *BackingImageManagerController) createBackingImageManagerPod(bim *longho
if err != nil {
return err
}

if _, err := c.ds.CreatePod(podManifest); err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
Expand Down Expand Up @@ -902,6 +903,7 @@ func (c *BackingImageManagerController) generateBackingImageManagerPodManifest(b
podSpec.Annotations[nadAnnot] = types.CreateCniAnnotationFromSetting(storageNetwork)
}

types.AddGoCoverDirToPod(podSpec)
return podSpec, nil
}

Expand Down
5 changes: 5 additions & 0 deletions controller/backup_target_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ func (btc *BackupTargetController) cleanUpAllMounts(backupTarget *longhorn.Backu
return err
}
defer engineClientProxy.Close()
// cleanup mount points in instance-manager
if err := engineClientProxy.CleanupBackupMountPoints(); err != nil {
return err
}
// clean mount points in longhorn-manager
err = backupTargetClient.BackupCleanUpAllMounts()
return err
}
Expand Down
1 change: 1 addition & 0 deletions controller/engine_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ func (ic *EngineImageController) createEngineImageDaemonSetSpec(ei *longhorn.Eng
},
}
}
types.AddGoCoverDirToDaemonSet(d)

return d, nil
}
Expand Down
1 change: 1 addition & 0 deletions controller/instance_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ func (imc *InstanceManagerController) createInstanceManagerPodSpec(im *longhorn.
},
})
}
types.AddGoCoverDirToPod(podSpec)

return podSpec, nil
}
Expand Down
8 changes: 7 additions & 1 deletion controller/share_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,12 @@ func (c *ShareManagerController) syncShareManagerVolume(sm *longhorn.ShareManage
}
return nil
} else if sm.Status.State == longhorn.ShareManagerStateRunning {
return c.mountShareManagerVolume(sm)
err := c.mountShareManagerVolume(sm)
if err != nil {
log.WithError(err).Error("Failed to mount share manager volume")
sm.Status.State = longhorn.ShareManagerStateError
}
return nil
}

// in a single node cluster, there is no other manager that can claim ownership so we are prevented from creation
Expand Down Expand Up @@ -979,6 +984,7 @@ func (c *ShareManagerController) createPodManifest(sm *longhorn.ShareManager, an
if resourceReq != nil {
podSpec.Spec.Containers[0].Resources = *resourceReq
}
types.AddGoCoverDirToPod(podSpec)

return podSpec
}
Expand Down
9 changes: 8 additions & 1 deletion csi/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand All @@ -15,6 +16,12 @@ const (
CryptoKeyDefaultHash = "sha256"
CryptoKeyDefaultSize = "256"
CryptoDefaultPBKDF = "argon2i"

// Luks2MinimalVolumeSize the minimal volume size for the LUKS2format encryption.
// https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions
// Section 10.10 What about the size of the LUKS2 header
// The default size is 16MB
Luks2MinimalVolumeSize = 16 * 1024 * 1024
)

// EncryptParams keeps the customized cipher options from the secret CR
Expand Down Expand Up @@ -67,7 +74,7 @@ func VolumeMapper(volume string) string {
func EncryptVolume(devicePath, passphrase string, cryptoParams *EncryptParams) error {
logrus.Infof("Encrypting device %s with LUKS", devicePath)
if _, err := luksFormat(devicePath, passphrase, cryptoParams); err != nil {
return fmt.Errorf("failed to encrypt device %s with LUKS: %w", devicePath, err)
return errors.Wrapf(err, "failed to encrypt device %s with LUKS", devicePath)
}
return nil
}
Expand Down
14 changes: 8 additions & 6 deletions csi/crypto/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func luksFormat(devicePath, passphrase string, cryptoParams *EncryptParams) (std
}

func luksResize(volume, passphrase string) (stdout string, err error) {
return cryptSetupWithPassphrase(passphrase,
"resize", volume)
return cryptSetupWithPassphrase(passphrase, "resize", volume)
}

func luksStatus(volume string) (stdout string, err error) {
Expand All @@ -58,15 +57,18 @@ func cryptSetupWithPassphrase(passphrase string, args ...string) (stdout string,
defer cancel()
cmd := exec.CommandContext(ctx, "nsenter", nsArgs...)

var stdoutBuf bytes.Buffer
cmd.Stdout = &stdoutBuf
stdoutBuf := &bytes.Buffer{}
stderrBuf := &bytes.Buffer{}
cmd.Stdout = stdoutBuf
cmd.Stderr = stderrBuf

if len(passphrase) > 0 {
cmd.Stdin = strings.NewReader(passphrase)
}

output := stdoutBuf.String()
if err := cmd.Run(); err != nil {
return output, errors.Wrapf(err, "failed to run cryptsetup args: %v output: %v", args, output)
return stdoutBuf.String(), errors.Wrapf(err, "failed to run cryptsetup, args: %v, stdout: %v, stderr: %v",
args, stdoutBuf.String(), stderrBuf.String())
}

return stdoutBuf.String(), nil
Expand Down
1 change: 1 addition & 0 deletions csi/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ func NewPluginDeployment(namespace, serviceAccount, nodeDriverRegistrarImage, li
},
}
}
types.AddGoCoverDirToDaemonSet(daemonSet)

return &PluginDeployment{
daemonSet: daemonSet,
Expand Down
6 changes: 6 additions & 0 deletions datastore/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/longhorn/longhorn-manager/csi/crypto"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

Expand Down Expand Up @@ -628,6 +629,11 @@ func CheckVolume(v *longhorn.Volume) error {
if v.Name == "" || size == 0 || v.Spec.NumberOfReplicas == 0 {
return fmt.Errorf("BUG: missing required field %+v", v)
}

if v.Spec.Encrypted && size <= crypto.Luks2MinimalVolumeSize {
return fmt.Errorf("invalid volume size %v, need to be bigger than 16MiB, default LUKS2 header size for encryption", v.Spec.Size)
}

errs := validation.IsDNS1123Label(v.Name)
if len(errs) != 0 {
return fmt.Errorf("invalid volume name: %+v", errs)
Expand Down
6 changes: 6 additions & 0 deletions engineapi/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,9 @@ func (e *EngineBinary) BackupRestoreStatus(*longhorn.Engine) (map[string]*longho
}
return replicaStatusMap, nil
}

// CleanupBackupMountPoints calls engine binary
// TODO: Deprecated, replaced by gRPC proxy, just to match the interface
func (e *EngineBinary) CleanupBackupMountPoints() error {
return fmt.Errorf(ErrNotImplement)
}
4 changes: 4 additions & 0 deletions engineapi/enginesim.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,7 @@ func (e *EngineSimulator) ReplicaModeUpdate(engine *longhorn.Engine, url, mode s
func (e *EngineSimulator) MetricsGet(*longhorn.Engine) (*Metrics, error) {
return nil, fmt.Errorf(ErrNotImplement)
}

func (e *EngineSimulator) CleanupBackupMountPoints() error {
return fmt.Errorf(ErrNotImplement)
}
4 changes: 4 additions & 0 deletions engineapi/proxy_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ func (p *Proxy) BackupRestoreStatus(e *longhorn.Engine) (status map[string]*long
}
return status, nil
}

func (p *Proxy) CleanupBackupMountPoints() (err error) {
return p.grpcClient.CleanupBackupMountPoints()
}
2 changes: 2 additions & 0 deletions engineapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type EngineClient interface {
BackupRestore(engine *longhorn.Engine, backupTarget, backupName, backupVolume, lastRestored string, credential map[string]string, concurrentLimit int) error
BackupRestoreStatus(engine *longhorn.Engine) (map[string]*longhorn.RestoreStatus, error)

CleanupBackupMountPoints() error

MetricsGet(engine *longhorn.Engine) (*Metrics, error)
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ require (
github.com/longhorn/backing-image-manager v1.4.0-rc1.0.20230521151917-38ff27cc2cbb
github.com/longhorn/backupstore v0.0.0-20231114103026-af339bb498d3
github.com/longhorn/go-iscsi-helper v0.0.0-20231113050545-9df1e6b605c7
github.com/longhorn/go-spdk-helper v0.0.0-20231002161457-6c31a95f76e8
github.com/longhorn/go-spdk-helper v0.0.0-20231113055029-9acddd184246
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230914160943-b42224518443
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20231006015831-4dca206b03f0
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20231117031020-055db7ef0240
github.com/longhorn/longhorn-share-manager v1.4.0-rc1.0.20231115135615-fb85b56534a4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
Expand All @@ -64,7 +64,7 @@ require (
golang.org/x/net v0.17.0
golang.org/x/sys v0.13.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.54.0
google.golang.org/grpc v1.56.3
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.28.2
Expand Down
18 changes: 12 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
github.com/container-storage-interface/spec v1.8.0 h1:D0vhF3PLIZwlwZEf2eNbpujGCNwspwTYf2idJRJx4xI=
github.com/container-storage-interface/spec v1.8.0/go.mod h1:ROLik+GhPslwwWRNFF1KasPzroNARibH2rfz1rkg4H0=
Expand Down Expand Up @@ -735,6 +737,8 @@ github.com/envoyproxy/go-control-plane v0.10.3/go.mod h1:fJJn/j26vwOu972OllsvAgJ
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v0.6.7/go.mod h1:dyJXwwfPK2VSqiB9Klm1J6romD608Ba7Hij42vrOBCo=
github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0++PMirau2/yoOwVac3AbF2w=
github.com/envoyproxy/protoc-gen-validate v0.10.1 h1:c0g45+xCJhdgFGw7a5QAfdS4byAbud7miNWJ1WwEVf8=
github.com/envoyproxy/protoc-gen-validate v0.10.1/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss=
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
Expand Down Expand Up @@ -812,8 +816,9 @@ github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOW
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE=
github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -1030,12 +1035,12 @@ github.com/longhorn/backupstore v0.0.0-20231114103026-af339bb498d3 h1:z1+k7ANPYj
github.com/longhorn/backupstore v0.0.0-20231114103026-af339bb498d3/go.mod h1:JzuHEmLyQPhGuxtKpJ2vCXPfGbylXJiBVg4KLVKsj9c=
github.com/longhorn/go-iscsi-helper v0.0.0-20231113050545-9df1e6b605c7 h1:YOOhIENIfhVCOaD00oWFeothjP0UyItBScUmpwGg8TM=
github.com/longhorn/go-iscsi-helper v0.0.0-20231113050545-9df1e6b605c7/go.mod h1:xz30xMoSLdYxfUygCzM/s99CA8/LNrkcEULFWExhqz4=
github.com/longhorn/go-spdk-helper v0.0.0-20231002161457-6c31a95f76e8 h1:tV7DKLG7xKdM3CratmRLF2JsOA1BpzFGj90nu0PiNCc=
github.com/longhorn/go-spdk-helper v0.0.0-20231002161457-6c31a95f76e8/go.mod h1:XoGXOYHw1KW3qdvTSimwY+Anyg5cPl6EVkjXxS25Upg=
github.com/longhorn/go-spdk-helper v0.0.0-20231113055029-9acddd184246 h1:Pry2QHJEqEy9jsRIaACmq/1Hre8N9wfE061+gQKspKg=
github.com/longhorn/go-spdk-helper v0.0.0-20231113055029-9acddd184246/go.mod h1:PCawMRVllTJnjbIYIC8axRfEI7aEhhjbsoBS/Y/EUYQ=
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230914160943-b42224518443 h1:4P/dmOAq8nMGg9vnXkT04NBdNidOCPXg2LM3J63ewn8=
github.com/longhorn/longhorn-engine v1.4.0-rc1.0.20230914160943-b42224518443/go.mod h1:zcfS53mU3LkxWAWf2MkHsa75Q4t01GmiW++mfp1+78M=
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20231006015831-4dca206b03f0 h1:s4fSDgPEnw76Uwbiy+L9RbL/OJ8qb/Uu6Ki0QhIiZT4=
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20231006015831-4dca206b03f0/go.mod h1:t3yBsQRDOL56ONfxEdzUkgCOqfmU0mF4B5MHMteYsOw=
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20231117031020-055db7ef0240 h1:ODDgqV+etH3mOI+Ss9C2jb5wHqll7kyet//bjBYhvaI=
github.com/longhorn/longhorn-instance-manager v1.4.0-rc1.0.20231117031020-055db7ef0240/go.mod h1:UEKMX5u3sHynT3KAddLUaxcrLABl8Y2H/NH8Oy4Kv3U=
github.com/longhorn/longhorn-share-manager v1.4.0-rc1.0.20231115135615-fb85b56534a4 h1:jf2jLuUZS5l7TyI1cNRqm7e9X/lrwBNsI16Q7P/o7JE=
github.com/longhorn/longhorn-share-manager v1.4.0-rc1.0.20231115135615-fb85b56534a4/go.mod h1:A/Z/YpW//hdULf+ZxelXQi8VEfAIIDRvEFvmv0xHSU0=
github.com/longhorn/longhorn-spdk-engine v0.0.0-20231005170812-e9b634e07e47 h1:hadV15fSF+akBFZ8dMQFscTsJUVpEC1t6Go3B28ZNYw=
Expand Down Expand Up @@ -2056,8 +2061,9 @@ google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCD
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw=
google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag=
google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g=
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
3 changes: 1 addition & 2 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM registry.suse.com/bci/bci-base:15.5

RUN zypper -n install curl nfs-client iproute2 bind-utils iputils telnet \
zip unzip e2fsprogs e2fsprogs-devel xfsprogs xfsprogs-devel cifs-utils && \
RUN zypper -n install iputils iproute2 nfs-client cifs-utils bind-utils e2fsprogs xfsprogs zip unzip && \
rm -rf /var/cache/zypp/*

COPY bin package/launch-manager package/nsmounter /usr/local/sbin/
Expand Down
77 changes: 77 additions & 0 deletions types/deploy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package types

import (
"os"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)

const (
LonghornManagerDaemonSetName = "longhorn-manager"
LonghornUIDeploymentName = "longhorn-ui"
Expand All @@ -11,3 +18,73 @@ const (
CSISnapshotterName = "csi-snapshotter"
CSIPluginName = "longhorn-csi-plugin"
)

// AddGoCoverDirToPod adds GOCOVERDIR env and host path volume to a pod.
// It's used to collect coverage data from a pod.
func AddGoCoverDirToPod(pod *corev1.Pod) {
if pod == nil || len(pod.Spec.Containers) == 0 {
return
}

goCoverDir := os.Getenv("GOCOVERDIR")
if goCoverDir == "" {
return
}

pod.Spec.Containers[0].Env = append(
pod.Spec.Containers[0].Env,
corev1.EnvVar{Name: "GOCOVERDIR", Value: goCoverDir},
)
pod.Spec.Containers[0].VolumeMounts = append(
pod.Spec.Containers[0].VolumeMounts,
corev1.VolumeMount{Name: "go-cover-dir", MountPath: goCoverDir},
)
hostPathType := corev1.HostPathDirectoryOrCreate
pod.Spec.Volumes = append(
pod.Spec.Volumes,
corev1.Volume{
Name: "go-cover-dir",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: goCoverDir,
Type: &hostPathType,
},
},
},
)
}

// AddGoCoverDirToDaemonSet adds GOCOVERDIR env and host path volume to a daemonset.
// It's used to collect coverage data from a daemonset.
func AddGoCoverDirToDaemonSet(daemonset *appsv1.DaemonSet) {
if daemonset == nil || len(daemonset.Spec.Template.Spec.Containers) == 0 {
return
}

goCoverDir := os.Getenv("GOCOVERDIR")
if goCoverDir == "" {
return
}

daemonset.Spec.Template.Spec.Containers[0].Env = append(
daemonset.Spec.Template.Spec.Containers[0].Env,
corev1.EnvVar{Name: "GOCOVERDIR", Value: goCoverDir},
)
daemonset.Spec.Template.Spec.Containers[0].VolumeMounts = append(
daemonset.Spec.Template.Spec.Containers[0].VolumeMounts,
corev1.VolumeMount{Name: "go-cover-dir", MountPath: goCoverDir},
)
hostPathType := corev1.HostPathDirectoryOrCreate
daemonset.Spec.Template.Spec.Volumes = append(
daemonset.Spec.Template.Spec.Volumes,
corev1.Volume{
Name: "go-cover-dir",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: goCoverDir,
Type: &hostPathType,
},
},
},
)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 570380c

Please sign in to comment.