Skip to content

Commit

Permalink
Merge branch 'master' into kopiaRepositoryServerWorkflowDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
r4rajat committed May 31, 2023
2 parents ecf87ed + 3a0b3cd commit 0d74e54
Show file tree
Hide file tree
Showing 19 changed files with 562 additions and 135 deletions.
2 changes: 1 addition & 1 deletion build/generate_crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CONTROLLER_GEN=${LOCALBIN}/controller-gen
## Tool Versions
CONTROLLER_TOOLS_VERSION=${1}

test -s ${CONTROLLER_GEN} || GOBIN=${LOCALBIN} go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
test -s ${CONTROLLER_GEN} || GOBIN=${LOCALBIN} go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_TOOLS_VERSION}
${CONTROLLER_GEN} crd webhook paths="github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1" output:crd:artifacts:config=pkg/customresource
32 changes: 32 additions & 0 deletions docs/tooling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ kanctl create
Available Commands:
actionset Create a new ActionSet or override a <parent> ActionSet
profile Create a new profile
repository-server Create a new kopia repository server
Flags:
--dry-run if set, resource YAML will be printed but not created
Expand Down Expand Up @@ -229,6 +230,37 @@ A new S3Compliant profile can be created using the s3compliant subcommand
secret 's3-secret-chst2' created
profile 's3-profile-5mmkj' created
Kopia Repository Server resource creation using ``kanctl create``
.. code-block:: bash
$ kanctl create repository-server --help
Create a new RepositoryServer
Usage:
kanctl create repository-server [flags]
Flags:
-a, --admin-user-access-secret string name of the secret having admin credentials to connect to connect to kopia repository server
-r, --kopia-repository-password-secret string name of the secret containing password for the kopia repository
-k, --kopia-repository-user string name of the user for accessing the kopia repository
-c, --location-creds-secret string name of the secret containing kopia repository storage credentials
-l, --location-secret string name of the secret containing kopia repository storage location details
-p, --prefix string prefix to be set in kopia repository
-t, --tls-secret string name of the tls secret needed for secure kopia client and kopia repository server communication
-u, --user string name of the user to be created for the kopia repository server
-s, --user-access-secret string name of the secret having access credentials of the users that can connect to kopia repository server
-w, --wait wait for the kopia repository server to be in ready state after creation
-h, --help help for repository-server
Global Flags:
--dry-run if set, resource YAML will be printed but not created
-n, --namespace string Override namespace obtained from kubectl context
--skip-validation if set, resource is not validated before creation
--verbose Display verbose output
.. _kanctlvalidate:
kanctl validate
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ replace (
// Direct and indirect dependencies are grouped together
require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.28
github.com/Azure/go-autorest/autorest v0.11.29
github.com/Azure/go-autorest/autorest/adal v0.9.23
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12
github.com/Azure/go-autorest/autorest/to v0.4.0
Expand Down Expand Up @@ -41,8 +41,8 @@ require (
github.com/openshift/api v0.0.0-20230406152840-ce21e3fe5da2
github.com/openshift/client-go v0.0.0-20230324103026-3f1513df25e0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.15.0
github.com/sirupsen/logrus v1.9.0
github.com/prometheus/client_golang v1.15.1
github.com/sirupsen/logrus v1.9.2
github.com/spf13/cobra v1.7.0
github.com/vmware/govmomi v0.30.4
go.uber.org/zap v1.24.0
Expand Down
13 changes: 7 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSW
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
github.com/Azure/go-autorest/autorest v0.9.6/go.mod h1:/FALq9T/kS7b5J5qsQ+RSTUdAmGFqi0vUdVNNx8q630=
github.com/Azure/go-autorest/autorest v0.11.24/go.mod h1:G6kyRlFnTuSbEYkQGawPfsCswgme4iYf6rfSKUDzbCc=
github.com/Azure/go-autorest/autorest v0.11.28 h1:ndAExarwr5Y+GaHE6VCaY1kyS/HwwGGyuimVhWsHOEM=
github.com/Azure/go-autorest/autorest v0.11.28/go.mod h1:MrkzG3Y3AH668QyF9KRk5neJnGgmhQ6krbhR8Q5eMvA=
github.com/Azure/go-autorest/autorest v0.11.29 h1:I4+HL/JDvErx2LjyzaVxllw2lRDB5/BT2Bm4g20iqYw=
github.com/Azure/go-autorest/autorest v0.11.29/go.mod h1:ZtEzC4Jy2JDrZLxvWs8LrBWEBycl1hbT1eknI8MtfAs=
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
github.com/Azure/go-autorest/autorest/adal v0.8.2/go.mod h1:ZjhuQClTqx435SRJ2iMlOxPYt3d2C/T/7TiQCVZSn3Q=
github.com/Azure/go-autorest/autorest/adal v0.9.18/go.mod h1:XVVeme+LZwABT8K5Lc3hA4nAe8LDBVle26gTrguhhPQ=
github.com/Azure/go-autorest/autorest/adal v0.9.22/go.mod h1:XuAbAEUv2Tta//+voMI038TrJBqjKam0me7qR+L8Cmk=
github.com/Azure/go-autorest/autorest/adal v0.9.23 h1:Yepx8CvFxwNKpH6ja7RZ+sKX+DWYNldbLiALMC3BTz8=
github.com/Azure/go-autorest/autorest/adal v0.9.23/go.mod h1:5pcMqFkdPhviJdlEy3kC/v1ZLnQl0MH6XA5YCcMhy4c=
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 h1:wkAZRgT/pn8HhFyzfe9UnqOjJYqlembgCTi72Bm/xKk=
Expand Down Expand Up @@ -440,8 +441,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM=
github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
Expand All @@ -460,8 +461,8 @@ github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/softlayer/softlayer-go v0.0.0-20190615201252-ba6e7f295217 h1:MFHQI+AYM6otrSP+l3dLhE2DjrSr5HXfV4mt4M6pjPs=
github.com/softlayer/softlayer-go v0.0.0-20190615201252-ba6e7f295217/go.mod h1:Cw4GTlQccdRGSEf6KiMju767x0NEHE0YIVPJSaXjlsw=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/cr/v1alpha1/repositoryserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ type Repository struct {
Hostname string `json:"hostname"`
// PasswordSecretRef has the password required to connect to kopia repository
PasswordSecretRef corev1.SecretReference `json:"passwordSecretRef"`
CacheSizeSettings CacheSizeSettings `json:"cacheSizeSettings,omitempty"`
}

// CacheSettings are the metadata/content cache size details
// that can be used while establishing connection to the kopia repository
type CacheSizeSettings struct {
Metadata string `json:"metadata"`
Content string `json:"content"`
}

// Server details required for starting the repository proxy server and initializing the repository client users
Expand Down
33 changes: 26 additions & 7 deletions pkg/controllers/repositoryserver/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@
package repositoryserver

import (
"strconv"

"github.com/kanisterio/kanister/pkg/kopia/command"
"github.com/kanisterio/kanister/pkg/kopia/repository"
)

const (
repoPasswordKey = "repo-password"
defaultRepoConfigFilePath = "/tmp/config.file"
defaultRepoLogDirectory = "/tmp/log.dir"
defaultCacheDirectory = "/tmp/cache.dir"
repoPasswordKey = "repo-password"
)

func (h *RepoServerHandler) connectToKopiaRepository() error {
contentCacheMB, metadataCacheMB := command.GetGeneralCacheSizeSettings()
contentCacheMB, metadataCacheMB, err := h.getRepositoryCacheSettings()
if err != nil {
return err
}
args := command.RepositoryCommandArgs{
CommandArgs: &command.CommandArgs{
RepoPassword: string(h.RepositoryServerSecrets.repositoryPassword.Data[repoPasswordKey]),
ConfigFilePath: command.DefaultConfigFilePath,
LogDirectory: command.DefaultCacheDirectory,
LogDirectory: command.DefaultLogDirectory,
},
CacheDirectory: defaultCacheDirectory,
CacheDirectory: command.DefaultCacheDirectory,
Hostname: h.RepositoryServer.Spec.Repository.Hostname,
ContentCacheMB: contentCacheMB,
MetadataCacheMB: metadataCacheMB,
Expand All @@ -52,3 +54,20 @@ func (h *RepoServerHandler) connectToKopiaRepository() error {
args,
)
}

func (h *RepoServerHandler) getRepositoryCacheSettings() (contentCacheMB, metadataCacheMB int, err error) {
contentCacheMB, metadataCacheMB = command.GetGeneralCacheSizeSettings()
if h.RepositoryServer.Spec.Repository.CacheSizeSettings.Content != "" {
contentCacheMB, err = strconv.Atoi(h.RepositoryServer.Spec.Repository.CacheSizeSettings.Content)
if err != nil {
return
}
}
if h.RepositoryServer.Spec.Repository.CacheSizeSettings.Metadata != "" {
metadataCacheMB, err = strconv.Atoi(h.RepositoryServer.Spec.Repository.CacheSizeSettings.Metadata)
if err != nil {
return
}
}
return
}
2 changes: 1 addition & 1 deletion pkg/controllers/repositoryserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (h *RepoServerHandler) startRepoProxyServer(ctx context.Context) (err error
CommandArgs: &command.CommandArgs{
RepoPassword: "",
ConfigFilePath: command.DefaultConfigFilePath,
LogDirectory: command.DefaultCacheDirectory,
LogDirectory: command.DefaultLogDirectory,
},
ServerAddress: repoServerAddress,
TLSCertFile: tlsCertPath,
Expand Down
12 changes: 12 additions & 0 deletions pkg/customresource/repositoryserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ spec:
description: Repository has the details required by the repository
server to connect to kopia repository
properties:
cacheSizeSettings:
description: CacheSettings are the metadata/content cache size
details that can be used for establishing connection to the kopia repository
properties:
content:
type: string
metadata:
type: string
required:
- content
- metadata
type: object
hostname:
description: If specified, these values will be used by the controller
to override default hostname when connecting to the repository
Expand Down
1 change: 1 addition & 0 deletions pkg/kanctl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func newCreateCommand() *cobra.Command {
}
cmd.AddCommand(newActionSetCmd())
cmd.AddCommand(newProfileCommand())
cmd.AddCommand(newRepositoryServerCommand())
cmd.PersistentFlags().Bool(dryRunFlag, false, "if set, resource YAML will be printed but not created")
cmd.PersistentFlags().Bool(skipValidationFlag, false, "if set, resource is not validated before creation")
return cmd
Expand Down
Loading

0 comments on commit 0d74e54

Please sign in to comment.