Skip to content

Commit 1c618d6

Browse files
committed
refactor: Derive path of a patch file in a common package
1 parent f90bcaf commit 1c618d6

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

pkg/common/constants.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package common
2+
3+
import "path/filepath"
4+
5+
const (
6+
// PatchRootDirOnRemote is the directory on the machine where we write patches as files.
7+
// These files are later applied by one or more commands that run on the machine.
8+
PatchRootDirOnRemote = "/etc/caren"
9+
)
10+
11+
// ContainerdPatchDirOnRemote is the directory where we write containerd patches as files.
12+
// It is a subdirectory of the root patches directory.
13+
var ContainerdPatchDirOnRemote = filepath.Join(PatchRootDirOnRemote, "containerd")
14+
15+
// PatchPathOnRemote returns the absolute path of a patch on the machine.
16+
func PatchPathOnRemote(relativePath string) string {
17+
return filepath.Join(PatchRootDirOnRemote, relativePath)
18+
}
19+
20+
// ContainerdPatchPathOnRemote returns the absolute path of a containerd patch on the machine.
21+
func ContainerdPatchPathOnRemote(relativePath string) string {
22+
return (filepath.Join(ContainerdPatchDirOnRemote, relativePath))
23+
}

pkg/handlers/generic/mutation/containerdmetrics/metrics.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@ package containerdmetrics
44

55
import (
66
_ "embed"
7-
"path"
87

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

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

1713
var (
1814
//go:embed files/metrics-config.toml
1915
metricsConfigDropIn []byte
20-
metricsConfigDropInFileOnRemote = path.Join(
21-
containerdPatchesDirOnRemote,
22-
"metrics-config.toml",
23-
)
16+
metricsConfigDropInFileOnRemote = common.ContainerdPatchPathOnRemote("metrics-config.toml")
2417
)
2518

2619
func generateMetricsConfigDropIn() cabpkv1.File {

pkg/handlers/generic/mutation/imageregistries/credentials/credential_provider_install_files.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ import (
1010
"text/template"
1111

1212
cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
13+
14+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common"
1315
)
1416

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

1921
installKubeletCredentialProvidersScriptOnRemoteCommand = "/bin/bash " + installKubeletCredentialProvidersScriptOnRemote
22+
)
2023

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

pkg/handlers/generic/mutation/mirrors/mirror.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1818

1919
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
20+
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common"
2021
)
2122

2223
const (
@@ -25,7 +26,6 @@ const (
2526
secretKeyForMirrorCACert = "ca.crt"
2627

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

4141
//go:embed templates/containerd-registry-config-drop-in.toml
4242
containerdRegistryConfigDropIn []byte
43-
containerdRegistryConfigDropInFileOnRemote = path.Join(
44-
containerdPatchesDirOnRemote,
43+
containerdRegistryConfigDropInFileOnRemote = common.ContainerdPatchPathOnRemote(
4544
"registry-config.toml",
4645
)
4746

@@ -203,7 +202,7 @@ func generateContainerdApplyPatchesScript() ([]cabpkv1.File, string, error) {
203202
PatchDir string
204203
}{
205204
TOMLMergeImage: tomlMergeImage,
206-
PatchDir: containerdPatchesDirOnRemote,
205+
PatchDir: common.ContainerdPatchDirOnRemote,
207206
}
208207

209208
var b bytes.Buffer

0 commit comments

Comments
 (0)