Skip to content

Commit

Permalink
refactor: Derive path of a patch file in a common package
Browse files Browse the repository at this point in the history
  • Loading branch information
dlipovetsky committed May 13, 2024
1 parent f90bcaf commit 8a879ab
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
26 changes: 26 additions & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 Nutanix. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package common

import "path/filepath"

const (
// PatchRootDirOnRemote is the directory on the machine where we write patches as files.
// These files are later applied by one or more commands that run on the machine.
PatchRootDirOnRemote = "/etc/caren"
)

// ContainerdPatchDirOnRemote is the directory where we write containerd patches as files.
// It is a subdirectory of the root patches directory.
var ContainerdPatchDirOnRemote = filepath.Join(PatchRootDirOnRemote, "containerd")

// PatchPathOnRemote returns the absolute path of a patch on the machine.
func PatchPathOnRemote(relativePath string) string {
return filepath.Join(PatchRootDirOnRemote, relativePath)
}

// ContainerdPatchPathOnRemote returns the absolute path of a containerd patch on the machine.
func ContainerdPatchPathOnRemote(relativePath string) string {
return (filepath.Join(ContainerdPatchDirOnRemote, relativePath))
}
11 changes: 2 additions & 9 deletions pkg/handlers/generic/mutation/containerdmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ package containerdmetrics

import (
_ "embed"
"path"

cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
)

const (
// TODO Factor out this constant to a common package.
containerdPatchesDirOnRemote = "/etc/caren/containerd"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common"
)

var (
//go:embed files/metrics-config.toml
metricsConfigDropIn []byte
metricsConfigDropInFileOnRemote = path.Join(
containerdPatchesDirOnRemote,
"metrics-config.toml",
)
metricsConfigDropInFileOnRemote = common.ContainerdPatchPathOnRemote("metrics-config.toml")
)

func generateMetricsConfigDropIn() cabpkv1.File {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ import (
"text/template"

cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common"
)

const (
//nolint:gosec // Does not contain hard coded credentials.
installKubeletCredentialProvidersScriptOnRemote = "/etc/caren/install-kubelet-credential-providers.sh"
var (
installKubeletCredentialProvidersScriptOnRemote = common.PatchPathOnRemote(
"install-kubelet-credential-providers.sh")

installKubeletCredentialProvidersScriptOnRemoteCommand = "/bin/bash " + installKubeletCredentialProvidersScriptOnRemote
)

const (
//nolint:gosec // Does not contain hard coded credentials.
dynamicCredentialProviderImage = "ghcr.io/mesosphere/dynamic-credential-provider:v0.5.0"

Expand Down
7 changes: 3 additions & 4 deletions pkg/handlers/generic/mutation/mirrors/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common"
)

const (
Expand All @@ -25,7 +26,6 @@ const (
secretKeyForMirrorCACert = "ca.crt"

tomlMergeImage = "ghcr.io/mesosphere/toml-merge:v0.2.0"
containerdPatchesDirOnRemote = "/etc/caren/containerd"
containerdApplyPatchesScriptOnRemote = "/etc/containerd/apply-patches.sh"
containerdApplyPatchesScriptOnRemoteCommand = "/bin/bash " + containerdApplyPatchesScriptOnRemote
)
Expand All @@ -40,8 +40,7 @@ var (

//go:embed templates/containerd-registry-config-drop-in.toml
containerdRegistryConfigDropIn []byte
containerdRegistryConfigDropInFileOnRemote = path.Join(
containerdPatchesDirOnRemote,
containerdRegistryConfigDropInFileOnRemote = common.ContainerdPatchPathOnRemote(
"registry-config.toml",
)

Expand Down Expand Up @@ -203,7 +202,7 @@ func generateContainerdApplyPatchesScript() ([]cabpkv1.File, string, error) {
PatchDir string
}{
TOMLMergeImage: tomlMergeImage,
PatchDir: containerdPatchesDirOnRemote,
PatchDir: common.ContainerdPatchDirOnRemote,
}

var b bytes.Buffer
Expand Down

0 comments on commit 8a879ab

Please sign in to comment.