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

OCPEDGE-1126: feat: make lvms microshift aware during vgmanager mounting #638

Merged
merged 1 commit into from
Jun 24, 2024
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
11 changes: 8 additions & 3 deletions internal/cluster/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync/atomic"

configv1 "github.com/openshift/api/config/v1"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -16,8 +17,9 @@ import (
type Type string

const (
TypeOCP Type = "openshift"
TypeOther Type = "other"
TypeOCP Type = "openshift"
TypeOther Type = "other"
TypeMicroShift Type = "microshift"
)

type TypeResolver interface {
Expand Down Expand Up @@ -64,8 +66,11 @@ func (r DefaultTypeResolver) GetType(ctx context.Context) (Type, error) {
logger.Info("Openshift Infrastructure not found, setting cluster type to other")
return TypeOther, nil
}

if meta.IsNoMatchError(err) {
if err := r.Get(ctx, types.NamespacedName{Name: "microshift-version", Namespace: "kube-public"}, &v1.ConfigMap{}); err == nil {
logger.Info("Microshift Version ConfigMap found, setting cluster type to MicroShift")
return TypeMicroShift, nil
}
logger.Info("Openshift Infrastructure not available in the cluster, setting cluster type to other")
return TypeOther, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/lvmcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (r *Reconciler) reconcile(ctx context.Context, instance *lvmv1alpha1.LVMClu

resources := []resource.Manager{
resource.CSIDriver(),
resource.VGManager(),
resource.VGManager(r.ClusterType),
resource.LVMVGs(),
resource.LVMVGNodeStatus(),
resource.TopoLVMStorageClass(),
Expand Down Expand Up @@ -333,7 +333,7 @@ func (r *Reconciler) processDelete(ctx context.Context, instance *lvmv1alpha1.LV
resource.LVMVGs(),
resource.LVMVGNodeStatus(),
resource.CSIDriver(),
resource.VGManager(),
resource.VGManager(r.ClusterType),
}

if r.ClusterType == cluster.TypeOCP {
Expand Down
12 changes: 9 additions & 3 deletions internal/controllers/lvmcluster/resource/vgmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ import (
"fmt"

lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1"
"github.com/openshift/lvm-operator/internal/cluster"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
cutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func VGManager() Manager {
return vgManager{}
func VGManager(clusterType cluster.Type) Manager {
return vgManager{
clusterType: clusterType,
}
}

type vgManager struct{}
type vgManager struct {
clusterType cluster.Type
}

var _ Manager = vgManager{}

Expand All @@ -50,6 +55,7 @@ func (v vgManager) EnsureCreated(r Reconciler, ctx context.Context, lvmCluster *
// get desired daemonset spec
dsTemplate := newVGManagerDaemonset(
lvmCluster,
v.clusterType,
r.GetNamespace(),
r.GetImageName(),
r.GetVGManagerCommand(),
Expand Down
15 changes: 13 additions & 2 deletions internal/controllers/lvmcluster/resource/vgmanager_daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1"
"github.com/openshift/lvm-operator/internal/cluster"
"github.com/openshift/lvm-operator/internal/controllers/constants"
"github.com/openshift/lvm-operator/internal/controllers/lvmcluster/selector"
"github.com/openshift/lvm-operator/internal/controllers/vgmanager/lvmd"
Expand Down Expand Up @@ -205,15 +206,25 @@ var (
)

// newVGManagerDaemonset returns the desired vgmanager daemonset for a given LVMCluster
func newVGManagerDaemonset(lvmCluster *lvmv1alpha1.LVMCluster, namespace, vgImage string, command, args []string) appsv1.DaemonSet {
func newVGManagerDaemonset(
lvmCluster *lvmv1alpha1.LVMCluster,
clusterType cluster.Type,
namespace, vgImage string,
command, args []string,
) appsv1.DaemonSet {
// aggregate nodeSelector and tolerations from all deviceClasses
confMapVolume := LVMDConfMapVol
if clusterType == cluster.TypeMicroShift {
confMapVolume.VolumeSource.HostPath.Path = filepath.Dir(lvmd.MicroShiftFileConfigPath)
}

nodeSelector, tolerations := selector.ExtractNodeSelectorAndTolerations(lvmCluster)
volumes := []corev1.Volume{
RegistrationVol,
NodePluginVol,
CSIPluginVol,
PodVol,
LVMDConfMapVol,
confMapVolume,
DevHostDirVol,
UDevHostDirVol,
SysHostDirVol,
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/lvmcluster/vgmanager_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"testing"

"github.com/openshift/lvm-operator/internal/cluster"
"github.com/openshift/lvm-operator/internal/controllers/lvmcluster/logpassthrough"
"github.com/openshift/lvm-operator/internal/controllers/lvmcluster/resource"
"gotest.tools/v3/assert"
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestVGManagerEnsureCreated(t *testing.T) {
Spec: testCase.lvmclusterSpec,
}
r := newFakeReconciler(t, lvmcluster)
var unit = resource.VGManager()
var unit = resource.VGManager(cluster.TypeOCP)
err := unit.EnsureCreated(r, log.IntoContext(context.Background(), testr.New(t)), lvmcluster)
assert.NilError(t, err, "running EnsureCreated")
ds := &appsv1.DaemonSet{}
Expand Down
8 changes: 5 additions & 3 deletions internal/controllers/vgmanager/lvmd/lvmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ var (
)

const (
DefaultFileConfigDir = "/etc/topolvm"
DefaultFileConfigPath = DefaultFileConfigDir + "/lvmd.yaml"
maxReadLength = 2 * 1 << 20 // 2MB
DefaultFileConfigDir = "/etc/topolvm"
MicroShiftFileConfigDir = "/etc/microshift"
DefaultFileConfigPath = DefaultFileConfigDir + "/lvmd.yaml"
MicroShiftFileConfigPath = MicroShiftFileConfigDir + "/lvmd.yaml"
maxReadLength = 2 * 1 << 20 // 2MB
)

func DefaultConfigurator() *CachedFileConfig {
Expand Down