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

OCPVE-677: chore: separate lvmd package from vgmanager #411

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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ e2e: ginkgo ## Build and run e2e tests.

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.13.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions bundle/manifests/lvm.topolvm.io_lvmclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.13.0
creationTimestamp: null
name: lvmclusters.lvm.topolvm.io
spec:
Expand Down Expand Up @@ -176,10 +176,12 @@ spec:
type: object
type: array
type: object
x-kubernetes-map-type: atomic
type: array
required:
- nodeSelectorTerms
type: object
x-kubernetes-map-type: atomic
thinPoolConfig:
description: ThinPoolConfig contains configurations for
the thin-pool
Expand Down Expand Up @@ -333,5 +335,5 @@ status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
conditions: null
storedVersions: null
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.13.0
creationTimestamp: null
name: lvmvolumegroupnodestatuses.lvm.topolvm.io
spec:
Expand Down Expand Up @@ -71,5 +71,5 @@ status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
conditions: null
storedVersions: null
8 changes: 5 additions & 3 deletions bundle/manifests/lvm.topolvm.io_lvmvolumegroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.13.0
creationTimestamp: null
name: lvmvolumegroups.lvm.topolvm.io
spec:
Expand Down Expand Up @@ -137,10 +137,12 @@ spec:
type: object
type: array
type: object
x-kubernetes-map-type: atomic
type: array
required:
- nodeSelectorTerms
type: object
x-kubernetes-map-type: atomic
thinPoolConfig:
description: ThinPoolConfig contains configurations for the thin-pool
properties:
Expand Down Expand Up @@ -180,5 +182,5 @@ status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
conditions: null
storedVersions: null
2 changes: 2 additions & 0 deletions cmd/vgmanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"

lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1"
"github.com/openshift/lvm-operator/pkg/lvmd"
"github.com/openshift/lvm-operator/pkg/vgmanager"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -79,6 +80,7 @@ func main() {
if err = (&vgmanager.VGReconciler{
Client: mgr.GetClient(),
EventRecorder: mgr.GetEventRecorderFor(vgmanager.ControllerName),
LVMD: lvmd.DefaultConfigurator(),
Scheme: mgr.GetScheme(),
NodeName: os.Getenv("NODE_NAME"),
Namespace: os.Getenv("POD_NAMESPACE"),
Expand Down
12 changes: 3 additions & 9 deletions config/crd/bases/lvm.topolvm.io_lvmclusters.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: lvmclusters.lvm.topolvm.io
spec:
group: lvm.topolvm.io
Expand Down Expand Up @@ -174,10 +172,12 @@ spec:
type: object
type: array
type: object
x-kubernetes-map-type: atomic
type: array
required:
- nodeSelectorTerms
type: object
x-kubernetes-map-type: atomic
thinPoolConfig:
description: ThinPoolConfig contains configurations for
the thin-pool
Expand Down Expand Up @@ -327,9 +327,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
10 changes: 1 addition & 9 deletions config/crd/bases/lvm.topolvm.io_lvmvolumegroupnodestatuses.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: lvmvolumegroupnodestatuses.lvm.topolvm.io
spec:
group: lvm.topolvm.io
Expand Down Expand Up @@ -69,9 +67,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
12 changes: 3 additions & 9 deletions config/crd/bases/lvm.topolvm.io_lvmvolumegroups.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: lvmvolumegroups.lvm.topolvm.io
spec:
group: lvm.topolvm.io
Expand Down Expand Up @@ -139,10 +137,12 @@ spec:
type: object
type: array
type: object
x-kubernetes-map-type: atomic
type: array
required:
- nodeSelectorTerms
type: object
x-kubernetes-map-type: atomic
thinPoolConfig:
description: ThinPoolConfig contains configurations for the thin-pool
properties:
Expand Down Expand Up @@ -178,9 +178,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 0 additions & 2 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
2 changes: 0 additions & 2 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
creationTimestamp: null
name: validating-webhook-configuration
webhooks:
- admissionReviewVersions:
Expand Down
72 changes: 72 additions & 0 deletions pkg/lvmd/lvmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package lvmd

import (
"fmt"
"os"

"github.com/topolvm/topolvm/lvmd"
lvmdCMD "github.com/topolvm/topolvm/pkg/lvmd/cmd"
"sigs.k8s.io/yaml"
)

type Config = lvmdCMD.Config

type DeviceClass = lvmd.DeviceClass
type ThinPoolConfig = lvmd.ThinPoolConfig

var TypeThin = lvmd.TypeThin

const DefaultFileConfigPath = "/etc/topolvm/lvmd.yaml"

func DefaultConfigurator() FileConfig {
return NewFileConfigurator(DefaultFileConfigPath)
}

func NewFileConfigurator(path string) FileConfig {
return FileConfig{path: path}
}

type Configurator interface {
Load() (*Config, error)
Save(config *Config) error
Delete() error
}

type FileConfig struct {
path string
}

func (c FileConfig) Load() (*Config, error) {
cfgBytes, err := os.ReadFile(c.path)
if os.IsNotExist(err) {
// If the file does not exist, return nil for both
return nil, nil
} else if err != nil {
return nil, fmt.Errorf("failed to load config file %s: %w", c.path, err)
} else {
config := &Config{}
if err = yaml.Unmarshal(cfgBytes, config); err != nil {
return nil, fmt.Errorf("failed to unmarshal config file %s: %w", c.path, err)
}
return config, nil
}
}

func (c FileConfig) Save(config *Config) error {
out, err := yaml.Marshal(config)
if err == nil {
err = os.WriteFile(c.path, out, 0600)
}
if err != nil {
return fmt.Errorf("failed to save config file %s: %w", c.path, err)
}
return nil
}

func (c FileConfig) Delete() error {
err := os.Remove(c.path)
if err != nil {
return fmt.Errorf("failed to delete config file %s: %w", c.path, err)
}
return err
}
Loading