Skip to content

Commit c0a855c

Browse files
authored
Merge branch 'master' into kopiaRepositoryServerWorkflowDocs
2 parents 27889ed + a76c23f commit c0a855c

5 files changed

Lines changed: 405 additions & 269 deletions

File tree

pkg/apis/cr/v1alpha1/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Package v1alpha1 is the v1alpha1 version of the API.
44
// +groupName=cr.kanister.io
5+
// +versionName=v1alpha1
56
package v1alpha1
67

78
// While generating client files, we need code-generator package to be installed

pkg/apis/cr/v1alpha1/repositoryserver_types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,26 @@ type RepositoryServerSpec struct {
5151

5252
// Storage references the backend store where a repository already exists
5353
// and the credential necessary to connect to the backend store
54+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.secretRef) || has(self.secretRef)",message="secretRef field must not be allowed to be removed"
5455
type Storage struct {
5556
// SecretRef has the details of the object storage (location)
5657
// where the kopia would backup the data
58+
// +kubebuilder:validation:Optional
59+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
5760
SecretRef corev1.SecretReference `json:"secretRef"`
5861
// CredentialSecretRef stores the credentials required
5962
// to connect to the object storage specified in `SecretRef` field
6063
CredentialSecretRef corev1.SecretReference `json:"credentialSecretRef"`
6164
}
6265

6366
// Repository has the details required by the repository server to connect to kopia repository
67+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.rootPath) || has(self.rootPath)",message="rootPath field must not be allowed to be removed"
6468
type Repository struct {
65-
// Path for the repository,it will be relative sub path
69+
// Path for the repository, it will be a relative sub path
6670
// within the path prefix specified in the location
6771
// More info: https://kopia.io/docs/reference/command-line/common/#commands-to-manipulate-repository
72+
// +kubebuilder:validation:Optional
73+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
6874
RootPath string `json:"rootPath"`
6975
// If specified, these values will be used by the controller to
7076
// override default username when connecting to the
@@ -79,21 +85,27 @@ type Repository struct {
7985
CacheSizeSettings CacheSizeSettings `json:"cacheSizeSettings,omitempty"`
8086
}
8187

82-
// CacheSettings are the metadata/content cache size details
88+
// CacheSizeSettings are the metadata/content cache size details
8389
// that can be used while establishing connection to the kopia repository
8490
type CacheSizeSettings struct {
8591
Metadata string `json:"metadata"`
8692
Content string `json:"content"`
8793
}
8894

8995
// Server details required for starting the repository proxy server and initializing the repository client users
96+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.adminSecretRef) || has(self.adminSecretRef)",message="adminSecretRef field must not be allowed to be removed"
97+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.tlsSecretRef) || has(self.tlsSecretRef)",message="tlsSecretRef field must not be allowed to be removed"
9098
type Server struct {
9199
UserAccess UserAccess `json:"userAccess"`
92100
// AdminSecretRef has the username and password required to start the
93101
// kopia repository server
102+
// +kubebuilder:validation:Optional
103+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
94104
AdminSecretRef corev1.SecretReference `json:"adminSecretRef"`
95105
// TLSSecretRef has the certificates required for kopia repository
96106
// client server connection
107+
// +kubebuilder:validation:Optional
108+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
97109
TLSSecretRef corev1.SecretReference `json:"tlsSecretRef"`
98110
}
99111

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright 2023 The Kanister Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1alpha1
16+
17+
import (
18+
"testing"
19+
20+
"github.com/pkg/errors"
21+
. "gopkg.in/check.v1"
22+
"k8s.io/apimachinery/pkg/runtime"
23+
"k8s.io/apimachinery/pkg/runtime/serializer"
24+
)
25+
26+
const repoServerSpec = `
27+
apiVersion: cr.kanister.io/v1alpha1
28+
kind: RepositoryServer
29+
metadata:
30+
name: test-kopia-repo-server
31+
namespace: kanister
32+
spec:
33+
storage:
34+
secretRef:
35+
name: test-s3-location
36+
namespace: kanister
37+
credentialSecretRef:
38+
name: test-s3-creds
39+
namespace: kanister
40+
repository:
41+
rootPath: /test-repo-controller/
42+
passwordSecretRef:
43+
name: test-repo-pass
44+
namespace: kanister
45+
username: test-repository-user
46+
hostname: localhost
47+
server:
48+
adminSecretRef:
49+
name: test-repository-admin-user
50+
namespace: kanister
51+
tlsSecretRef:
52+
name: test-repository-server-tls-cert
53+
namespace: kanister
54+
userAccess:
55+
userAccessSecretRef:
56+
name: test-repository-server-user-access
57+
namespace: kanister
58+
username: test-kanister-user
59+
`
60+
61+
func TestRepositoryServer(t *testing.T) { TestingT(t) }
62+
63+
func (s *TypesSuite) TestRepositoryServerDecode(c *C) {
64+
rs, err := getRepositoryServerFromSpec([]byte(repoServerSpec))
65+
c.Assert(err, IsNil)
66+
c.Assert(rs, NotNil)
67+
c.Assert(rs.Spec.Storage.SecretRef.Name, Equals, "test-s3-location")
68+
c.Assert(rs.Spec.Storage.SecretRef.Namespace, Equals, "kanister")
69+
c.Assert(rs.Spec.Storage.CredentialSecretRef.Name, Equals, "test-s3-creds")
70+
c.Assert(rs.Spec.Storage.CredentialSecretRef.Namespace, Equals, "kanister")
71+
c.Assert(rs.Spec.Repository.RootPath, Equals, "/test-repo-controller/")
72+
c.Assert(rs.Spec.Repository.PasswordSecretRef.Name, Equals, "test-repo-pass")
73+
c.Assert(rs.Spec.Repository.PasswordSecretRef.Namespace, Equals, "kanister")
74+
c.Assert(rs.Spec.Repository.Username, Equals, "test-repository-user")
75+
c.Assert(rs.Spec.Repository.Hostname, Equals, "localhost")
76+
c.Assert(rs.Spec.Server.AdminSecretRef.Name, Equals, "test-repository-admin-user")
77+
c.Assert(rs.Spec.Server.AdminSecretRef.Namespace, Equals, "kanister")
78+
c.Assert(rs.Spec.Server.TLSSecretRef.Name, Equals, "test-repository-server-tls-cert")
79+
c.Assert(rs.Spec.Server.TLSSecretRef.Namespace, Equals, "kanister")
80+
c.Assert(rs.Spec.Server.UserAccess.UserAccessSecretRef.Name, Equals, "test-repository-server-user-access")
81+
c.Assert(rs.Spec.Server.UserAccess.UserAccessSecretRef.Namespace, Equals, "kanister")
82+
c.Assert(rs.Spec.Server.UserAccess.Username, Equals, "test-kanister-user")
83+
}
84+
85+
func getRepositoryServerFromSpec(spec []byte) (*RepositoryServer, error) {
86+
repositoryServer := &RepositoryServer{}
87+
d := serializer.NewCodecFactory(runtime.NewScheme()).UniversalDeserializer()
88+
if _, _, err := d.Decode([]byte(spec), nil, repositoryServer); err != nil {
89+
return nil, errors.Wrap(err, "Failed to decode RepositoryServer")
90+
}
91+
return repositoryServer, nil
92+
}

0 commit comments

Comments
 (0)