Skip to content

Commit

Permalink
Revert "Revert "Add unit tests for kopia repository server controller…
Browse files Browse the repository at this point in the history
…(PR #2)"" (#2180)

* Revert "Revert "Add unit tests for kopia repository server controller(PR #2) (#1997)" (#2178)"

This reverts commit 5d16f29.

* skip immuatability test for k8s version < 1.25

* check error is not nil for discovery client

* fix minor and major version variable names
  • Loading branch information
kale-amruta committed Jul 19, 2023
1 parent 1b4201f commit 2494994
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
# before running `make test`, to create some CRDs on the cluster.
- run: |
make install-csi-hostpath-driver
make install-minio
if: matrix.testSuite == 'test'
- run: make ${{ matrix.testSuite }}
build:
Expand Down
15 changes: 15 additions & 0 deletions build/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ if [ -n "${ERRS}" ]; then
fi
echo

check_dependencies() {
# Check if minio is already deployed
if helm status minio -n minio > /dev/null 2>&1 ; then
# Setting env vars to access MinIO
export S3_COMPLIANT_AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"
export S3_COMPLIANT_AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
export S3_COMPLIANT_AWS_REGION="us-west-2"
export S3_COMPLIANT_LOCATION_ENDPOINT="http://minio.minio.svc.cluster.local:9000"
else
echo "Please install MinIO using 'make install-minio' and try again."
exit 1
fi
}

check_dependencies
echo "Running tests:"
go test -v -installsuffix "static" -i ${TARGETS}
go test -v ${TARGETS} -list .
Expand Down
9 changes: 6 additions & 3 deletions pkg/controllers/repositoryserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ type RepoServerHandler struct {
}

func (h *RepoServerHandler) CreateOrUpdateOwnedResources(ctx context.Context) error {
if err := h.getSecretsFromCR(ctx); err != nil {
return errors.Wrap(err, "Failed to get Kopia API server secrets")
}

svc, err := h.reconcileService(ctx)
if err != nil {
return errors.Wrap(err, "Failed to reconcile service")
}
if err = h.getSecretsFromCR(ctx); err != nil {
return errors.Wrap(err, "Failed to get Kopia API server secrets")
}

envVars, pod, err := h.reconcilePod(ctx, svc)
if err != nil {
return errors.Wrap(err, "Failed to reconcile Kopia API server pod")
Expand Down Expand Up @@ -222,6 +224,7 @@ func (h *RepoServerHandler) updateServiceNameInPodLabels(pod *corev1.Pod, svc *c

func (h *RepoServerHandler) createPod(ctx context.Context, repoServerNamespace string, svc *corev1.Service) (*corev1.Pod, []corev1.EnvVar, error) {
podOverride, err := h.preparePodOverride(ctx)

if err != nil {
return nil, nil, err
}
Expand Down
73 changes: 73 additions & 0 deletions pkg/controllers/repositoryserver/repository_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2023 The Kanister 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 repositoryserver

import (
"github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/kopia/command"
"github.com/kanisterio/kanister/pkg/testutil"
. "gopkg.in/check.v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

func (s *RepoServerControllerSuite) TestCacheSizeConfiguration(c *C) {
repositoryServer := testutil.GetTestKopiaRepositoryServerCR(s.repoServerControllerNamespace)
setRepositoryServerSecretsInCR(&s.repoServerSecrets, repositoryServer)

defaultcontentCacheMB, defaultmetadataCacheMB := command.GetGeneralCacheSizeSettings()

repoServerHandler := RepoServerHandler{
Req: reconcile.Request{},
Reconciler: s.DefaultRepoServerReconciler,
KubeCli: s.kubeCli,
RepositoryServer: repositoryServer,
}

// Test if Default cache size settings are set
contentCacheMB, metadataCacheMB, err := repoServerHandler.getRepositoryCacheSettings()
c.Assert(err, IsNil)
c.Assert(contentCacheMB, Equals, defaultcontentCacheMB)
c.Assert(metadataCacheMB, Equals, defaultmetadataCacheMB)

// Test if configfured cache size settings are set
repositoryServer.Spec.Repository.CacheSizeSettings = v1alpha1.CacheSizeSettings{
Metadata: "1000",
Content: "1100",
}
contentCacheMB, metadataCacheMB, err = repoServerHandler.getRepositoryCacheSettings()
c.Assert(err, IsNil)
c.Assert(contentCacheMB, Equals, 1100)
c.Assert(metadataCacheMB, Equals, 1000)

// Check if default Content Cache size is set
repositoryServer.Spec.Repository.CacheSizeSettings = v1alpha1.CacheSizeSettings{
Metadata: "1000",
Content: "",
}
contentCacheMB, metadataCacheMB, err = repoServerHandler.getRepositoryCacheSettings()
c.Assert(err, IsNil)
c.Assert(contentCacheMB, Equals, defaultcontentCacheMB)
c.Assert(metadataCacheMB, Equals, 1000)

// Check if default Metadata Cache size is set
repositoryServer.Spec.Repository.CacheSizeSettings = v1alpha1.CacheSizeSettings{
Metadata: "",
Content: "1100",
}
contentCacheMB, metadataCacheMB, err = repoServerHandler.getRepositoryCacheSettings()
c.Assert(err, IsNil)
c.Assert(contentCacheMB, Equals, 1100)
c.Assert(metadataCacheMB, Equals, defaultmetadataCacheMB)
}
Loading

0 comments on commit 2494994

Please sign in to comment.