Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to override kanister-tools image in repo controller #2261

Merged
merged 7 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions helm/kanister-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ on the value of bpValidatingWebhook.enabled
{{ .Values.controller.service.insecuredPort }}
{{- end -}}
{{- end -}}

{{/*
Define a custom kanister-tools image
*/}}
{{- define "kanister-tools.image" -}}
{{- printf "%s:%s" (.Values.kanisterToolsImage.image) (.Values.kanisterToolsImage.tag) -}}
{{- end -}}
4 changes: 4 additions & 0 deletions helm/kanister-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ spec:
value: {{ .Values.repositoryServerController.logLevel }}
- name: CREATEORUPDATE_CRDS
value: {{ .Values.controller.updateCRDs | quote }}
{{- if .Values.kanisterToolsImage.override }}
- name: KANISTER_TOOLS
value: {{ include "kanister-tools.image" . }}
{{- end }}
{{- if .Values.resources }}
resources:
{{ toYaml .Values.resources | indent 12 }}
Expand Down
4 changes: 4 additions & 0 deletions helm/kanister-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ repositoryServerControllerImage:
name: repo-server-controller
tag: 0.93.0
pullPolicy: IfNotPresent
kanisterToolsImage:
override: false
pavannd1 marked this conversation as resolved.
Show resolved Hide resolved
image: ghcr.io/kanisterio/kanister-tools
tag: 0.93.0
rbac:
create: true
serviceAccount:
Expand Down
17 changes: 17 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 consts

const (
Expand Down Expand Up @@ -30,3 +44,6 @@ const RepositoryServerResourceNamePlural = "repositoryservers"

const LatestKanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:v9.99.9-dev"
const KanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:0.93.0"

// KanisterToolsImageEnvName is used to set up a custom kanister-tools image
const KanisterToolsImageEnvName = "KANISTER_TOOLS"
27 changes: 27 additions & 0 deletions pkg/consts/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 consts

import "os"

// GetKanisterToolsImage returns the KanisterTools image
// Returns the value of the KANISTER_TOOLS env if set
// Otherwise, returns the default released version.
func GetKanisterToolsImage() string {
if val, ok := os.LookupEnv(KanisterToolsImageEnvName); ok {
return val
}
return KanisterToolsImage
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func (s *RepoServerControllerSuite) SetUpSuite(c *C) {
// We need to set this up since we are not creating controller in a pod
os.Setenv("HOSTNAME", controllerPodName)
os.Setenv("POD_SERVICE_ACCOUNT", defaultServiceAccount)
// Set KANISTER_TOOLS env to override and use dev image
os.Setenv(consts.KanisterToolsImageEnvName, consts.LatestKanisterToolsImage)
err = mgr.Start(ctx)
c.Assert(err, IsNil)
}(ctx)
Expand Down Expand Up @@ -447,7 +449,7 @@ func (s *RepoServerControllerSuite) waitForRepoServerInfoUpdateInCR(repoServerNa
}

func (s *RepoServerControllerSuite) waitOnRepositoryServerState(c *C, reposerverName string) (v1alpha1.RepositoryServerProgress, error) {
ctxTimeout := 15 * time.Minute
ctxTimeout := 5 * time.Minute
ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
defer cancel()
var repoServerState v1alpha1.RepositoryServerProgress
Expand Down Expand Up @@ -517,6 +519,8 @@ func getTestKanisterToolsPod(podName string) (pod *v1.Pod) {
}

func (s *RepoServerControllerSuite) TearDownSuite(c *C) {
err := os.Unsetenv(consts.KanisterToolsImageEnvName)
c.Assert(err, IsNil)
if s.repoServerControllerNamespace != "" {
err := s.kubeCli.CoreV1().Namespaces().Delete(context.TODO(), s.repoServerControllerNamespace, metav1.DeleteOptions{})
c.Assert(err, IsNil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/repositoryserver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func getPodOptions(namespace string, podOverride map[string]interface{}, svc *co
return &kube.PodOptions{
Namespace: namespace,
GenerateName: fmt.Sprintf("%s-", repoServerPod),
Image: consts.KanisterToolsImage,
Image: consts.GetKanisterToolsImage(),
ContainerName: repoServerPodContainerName,
Command: []string{"bash", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
Expand Down
3 changes: 2 additions & 1 deletion pkg/function/backup_data_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/format"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
Expand Down Expand Up @@ -65,7 +66,7 @@ func backupDataStats(ctx context.Context, cli kubernetes.Interface, tp param.Tem
options := &kube.PodOptions{
Namespace: namespace,
GenerateName: jobPrefix,
Image: getKanisterToolsImage(),
Image: consts.GetKanisterToolsImage(),
Command: []string{"sh", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/function/checkRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/restic"
Expand Down Expand Up @@ -49,7 +50,7 @@ func CheckRepository(ctx context.Context, cli kubernetes.Interface, tp param.Tem
options := &kube.PodOptions{
Namespace: namespace,
GenerateName: jobPrefix,
Image: getKanisterToolsImage(),
Image: consts.GetKanisterToolsImage(),
Command: []string{"sh", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/client-go/kubernetes"

kanister "github.com/kanisterio/kanister/pkg"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/format"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/log"
Expand Down Expand Up @@ -73,7 +74,7 @@ func copyVolumeData(ctx context.Context, cli kubernetes.Interface, tp param.Temp
options := &kube.PodOptions{
Namespace: namespace,
GenerateName: CopyVolumeDataJobPrefix,
Image: getKanisterToolsImage(),
Image: consts.GetKanisterToolsImage(),
Command: []string{"sh", "-c", "tail -f /dev/null"},
Volumes: map[string]string{pvc: mountPoint},
PodOverride: podOverride,
Expand Down
3 changes: 2 additions & 1 deletion pkg/function/delete_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/format"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
Expand Down Expand Up @@ -69,7 +70,7 @@ func deleteData(ctx context.Context, cli kubernetes.Interface, tp param.Template
options := &kube.PodOptions{
Namespace: namespace,
GenerateName: jobPrefix,
Image: getKanisterToolsImage(),
Image: consts.GetKanisterToolsImage(),
Command: []string{"sh", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/function/describe_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/format"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
Expand Down Expand Up @@ -67,7 +68,7 @@ func describeBackups(ctx context.Context, cli kubernetes.Interface, tp param.Tem
options := &kube.PodOptions{
Namespace: namespace,
GenerateName: jobPrefix,
Image: getKanisterToolsImage(),
Image: consts.GetKanisterToolsImage(),
Command: []string{"sh", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
}
Expand Down
12 changes: 1 addition & 11 deletions pkg/function/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package function
import (
"bytes"
"context"
"os"
"path"
"strings"

Expand All @@ -27,18 +26,9 @@ import (

const (
// FunctionOutputVersion returns version
FunctionOutputVersion = "version"
kanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:0.93.0"
kanisterToolsImageEnvName = "KANISTER_TOOLS"
FunctionOutputVersion = "version"
)

func getKanisterToolsImage() string {
if val, ok := os.LookupEnv(kanisterToolsImageEnvName); ok {
return val
}
return kanisterToolsImage
}

// ValidateCredentials verifies if the given credentials have appropriate values set
func ValidateCredentials(creds *param.Credential) error {
if creds == nil {
Expand Down