diff --git a/internal/cluster/type.go b/internal/cluster/type.go index a5ae3ee37..c924ff2ef 100644 --- a/internal/cluster/type.go +++ b/internal/cluster/type.go @@ -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" @@ -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 { @@ -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 } diff --git a/internal/controllers/lvmcluster/controller.go b/internal/controllers/lvmcluster/controller.go index 07b714cd5..65d024710 100644 --- a/internal/controllers/lvmcluster/controller.go +++ b/internal/controllers/lvmcluster/controller.go @@ -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(), @@ -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 { diff --git a/internal/controllers/lvmcluster/resource/vgmanager.go b/internal/controllers/lvmcluster/resource/vgmanager.go index 9818a41b9..012069449 100644 --- a/internal/controllers/lvmcluster/resource/vgmanager.go +++ b/internal/controllers/lvmcluster/resource/vgmanager.go @@ -21,6 +21,7 @@ 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" @@ -28,11 +29,15 @@ import ( "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{} @@ -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(), diff --git a/internal/controllers/lvmcluster/resource/vgmanager_daemonset.go b/internal/controllers/lvmcluster/resource/vgmanager_daemonset.go index 2a62e1a3c..ad63ce240 100644 --- a/internal/controllers/lvmcluster/resource/vgmanager_daemonset.go +++ b/internal/controllers/lvmcluster/resource/vgmanager_daemonset.go @@ -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" @@ -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, diff --git a/internal/controllers/lvmcluster/vgmanager_resource_test.go b/internal/controllers/lvmcluster/vgmanager_resource_test.go index bb2f6b250..ec95b6efd 100644 --- a/internal/controllers/lvmcluster/vgmanager_resource_test.go +++ b/internal/controllers/lvmcluster/vgmanager_resource_test.go @@ -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" @@ -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{} diff --git a/internal/controllers/vgmanager/lvmd/lvmd.go b/internal/controllers/vgmanager/lvmd/lvmd.go index 3d7fce641..44ad2ce0b 100644 --- a/internal/controllers/vgmanager/lvmd/lvmd.go +++ b/internal/controllers/vgmanager/lvmd/lvmd.go @@ -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 {