Skip to content

Commit

Permalink
Add kubeconfig path for IBM Managed OpenShift (#810)
Browse files Browse the repository at this point in the history
IBM Managed OpenShift seems to use "/etc/kubernetes/kubelet-kubeconfig"
instead of the traditional "/var/lib/kubelet/kubeconfig" kubelet config
path.

Other changes:
  - fix a crash when kubelet's kubeconfig is not found and in-cluster
    config is used instead

Resolves: OCPBUGS-19795

Co-authored-by: Jiri Mencak <jmencak@users.noreply.github.com>
  • Loading branch information
jmencak and jmencak committed Sep 26, 2023
1 parent 78c64b2 commit 4ca8e91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions assets/tuned/manifests/ds-tuned.yaml
Expand Up @@ -44,6 +44,10 @@ spec:
- mountPath: /etc/sysconfig
name: etc-sysconfig
mountPropagation: HostToContainer
- mountPath: /etc/kubernetes
name: etc-kubernetes
mountPropagation: HostToContainer
readOnly: true
- mountPath: /etc/sysctl.d
name: etc-sysctl-d
mountPropagation: HostToContainer
Expand Down Expand Up @@ -96,6 +100,10 @@ spec:
path: /etc/sysconfig
type: Directory
name: etc-sysconfig
- hostPath:
path: /etc/kubernetes
type: Directory
name: etc-kubernetes
- hostPath:
path: /etc/sysctl.d
type: Directory
Expand Down
22 changes: 19 additions & 3 deletions pkg/tuned/controller.go
Expand Up @@ -86,9 +86,6 @@ const (
wqKindDaemon = "daemon"
wqKindTuned = "tuned"
wqKindProfile = "profile"

// path to kubelet kubeconfig
kubeletKubeconfigPath = "/var/lib/kubelet/kubeconfig"
)

// Types
Expand Down Expand Up @@ -186,6 +183,21 @@ func parseCmdOpts() {

// Get a client from kubelet's kubeconfig to write to the Node object.
func getKubeClient() (kubernetes.Interface, error) {
var (
// paths to kubelet kubeconfig
kubeletKubeconfigPaths = []string{
"/var/lib/kubelet/kubeconfig", // traditional OCP
"/etc/kubernetes/kubelet-kubeconfig", // IBM Managed OpenShift, see OCPBUGS-19795
}
kubeletKubeconfigPath string
)

for _, kubeletKubeconfigPath = range kubeletKubeconfigPaths {
if _, err := os.Stat(kubeletKubeconfigPath); err == nil {
break
}
}

config, err := clientcmd.BuildConfigFromFlags("", kubeletKubeconfigPath)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1006,6 +1018,10 @@ func (c *Controller) updateTunedProfile() (err error) {
}

node, err := c.getNodeForProfile(getNodeName())
if err != nil {
return err
}

if node.ObjectMeta.Annotations == nil {
node.ObjectMeta.Annotations = map[string]string{}
}
Expand Down

0 comments on commit 4ca8e91

Please sign in to comment.