Skip to content

Commit

Permalink
iscsi,nfs,nvmeof: toml versioning
Browse files Browse the repository at this point in the history
Add a new "metadata" field to the promoter config, which stores a schema
version.
  • Loading branch information
chrboe committed Nov 6, 2023
1 parent c44ad61 commit 8723022
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/iscsi/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (i *ISCSI) DeleteVolume(ctx context.Context, iqn Iqn, lun int) (*ResourceCo
if rscCfg.Volumes[j].Number == lun {
err = i.cli.ResourceDefinitions.DeleteVolumeDefinition(ctx, iqn.WWN(), lun)
if err != nil && err != client.NotFoundError {
return nil, fmt.Errorf("failed to delete volume definition")
return nil, fmt.Errorf("failed to delete volume definition: %w", err)
}

rscCfg.Volumes = append(rscCfg.Volumes[:j], rscCfg.Volumes[j+1:]...)
Expand Down
4 changes: 4 additions & 0 deletions pkg/iscsi/resource_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

const (
DefaultISCSIPort = 3260
CurrentVersion = 1
)

type ResourceConfig struct {
Expand Down Expand Up @@ -399,5 +400,8 @@ func (r *ResourceConfig) ToPromoter(deployment []client.ResourceWithVolumes) (*r
TargetAs: "Requires",
},
},
Metadata: reactor.PromoterMetadata{
LinstorGatewaySchemaVersion: CurrentVersion,
},
}, nil
}
4 changes: 4 additions & 0 deletions pkg/nfs/resource_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
const (
ExportBasePath = "/srv/gateway-exports"
DefaultNFSPort = 2049
CurrentVersion = 1
)

var (
Expand Down Expand Up @@ -496,6 +497,9 @@ func (r *ResourceConfig) ToPromoter(deployment []client.ResourceWithVolumes) (*r
TargetAs: "BindsTo",
},
},
Metadata: reactor.PromoterMetadata{
LinstorGatewaySchemaVersion: CurrentVersion,
},
}, nil
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/nvmeof/resource_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import (
"github.com/LINBIT/linstor-gateway/pkg/reactor"
)

const IDFormat = "nvmeof-%s"
const DefaultPort = 4420
const (
IDFormat = "nvmeof-%s"
DefaultPort = 4420
CurrentVersion = 1
)

type ResourceConfig struct {
NQN Nqn `json:"nqn"`
Expand Down Expand Up @@ -245,6 +248,9 @@ func (r *ResourceConfig) ToPromoter(deployment []client.ResourceWithVolumes) (*r
TargetAs: "Requires",
},
},
Metadata: reactor.PromoterMetadata{
LinstorGatewaySchemaVersion: CurrentVersion,
},
}, nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/reactor/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ type Config struct {
Promoter []PromoterConfig `toml:"promoter,omitempty"`
}

// PromoterMetadata is a custom extension to the drbd-reactor config format.
// It stores fields specific to linstor-gateway.
type PromoterMetadata struct {
LinstorGatewaySchemaVersion int `toml:"linstor-gateway-schema-version"`
}

// PromoterConfig is the configuration for drbd-reactors "promoter" plugin.
type PromoterConfig struct {
ID string `toml:"id"`
Resources map[string]PromoterResourceConfig `toml:"resources,omitempty"`
Metadata PromoterMetadata `toml:"metadata,omitempty"`
}

// DeployedResources fetches the current state of the resources referenced in the promoter config.
Expand Down
4 changes: 4 additions & 0 deletions pkg/upgrade/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func upgradeIscsi(ctx context.Context, linstor *client.Client, name string, forc
if err != nil {
return false, err
}
if cfg.Metadata.LinstorGatewaySchemaVersion > iscsi.CurrentVersion {
return false, fmt.Errorf("schema version %d is not supported",
cfg.Metadata.LinstorGatewaySchemaVersion)
}

parsedCfg, err := iscsi.FromPromoter(cfg, resourceDefinition, volumeDefinitions)
if err != nil {
Expand Down

0 comments on commit 8723022

Please sign in to comment.