-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bala.FA <[email protected]>
- Loading branch information
1 parent
a3471d6
commit 7d99392
Showing
25 changed files
with
1,025 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
linters-settings: | ||
gofumpt: | ||
lang-version: "1.22" | ||
run: | ||
go: "1.22" | ||
|
||
misspell: | ||
locale: US | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// This file is part of MinIO DirectPV | ||
// Copyright (c) 2024 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
directpvtypes "github.com/minio/directpv/pkg/apis/directpv.min.io/types" | ||
"github.com/minio/directpv/pkg/client" | ||
drivepkg "github.com/minio/directpv/pkg/drive" | ||
"github.com/minio/directpv/pkg/types" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var ( | ||
forceFlag = false | ||
disablePrefetchFlag = false | ||
dryRunFlag = false | ||
) | ||
|
||
var repairCmd = &cobra.Command{ | ||
Use: "repair <DRIVE-ID>", | ||
Short: "Start drive repair.", | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
RunE: func(c *cobra.Command, args []string) error { | ||
switch len(args) { | ||
case 0: | ||
return errors.New("DRIVE-ID must be provided") | ||
case 1: | ||
default: | ||
return errors.New("only one DRIVE-ID must be provided") | ||
} | ||
return startRepair(c.Context(), args[0]) | ||
}, | ||
} | ||
|
||
func init() { | ||
repairCmd.PersistentFlags().BoolVar(&forceFlag, "force", forceFlag, "Force log zeroing") | ||
repairCmd.PersistentFlags().BoolVar(&disablePrefetchFlag, "disable-prefetch", disablePrefetchFlag, "Disable prefetching of inode and directory blocks") | ||
repairCmd.PersistentFlags().BoolVar(&dryRunFlag, "dry-run", dryRunFlag, "No modify mode") | ||
} | ||
|
||
func startRepair(ctx context.Context, driveID string) error { | ||
var cancel context.CancelFunc | ||
ctx, cancel = context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
drive, err := client.DriveClient().Get(ctx, driveID, metav1.GetOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if drive.Status.Status != directpvtypes.DriveStatusRepairing { | ||
drive.Status.Status = directpvtypes.DriveStatusRepairing | ||
} | ||
|
||
updatedDrive, err := client.DriveClient().Update(ctx, drive, metav1.UpdateOptions{TypeMeta: types.NewDriveTypeMeta()}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return drivepkg.Repair(ctx, updatedDrive, forceFlag, disablePrefetchFlag, dryRunFlag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// This file is part of MinIO DirectPV | ||
// Copyright (c) 2024 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"strings" | ||
|
||
"github.com/minio/directpv/pkg/admin" | ||
"github.com/minio/directpv/pkg/consts" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
forceFlag = false | ||
disablePrefetchFlag = false | ||
) | ||
|
||
var repairCmd = &cobra.Command{ | ||
Use: "repair DRIVE ...", | ||
Short: "Repair filesystem of drives", | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
Example: strings.ReplaceAll( | ||
`1. Repair drives | ||
$ kubectl {PLUGIN_NAME} repair 3b562992-f752-4a41-8be4-4e688ae8cd4c`, | ||
`{PLUGIN_NAME}`, | ||
consts.AppName, | ||
), | ||
Run: func(c *cobra.Command, args []string) { | ||
driveIDArgs = args | ||
if err := validateRepairCmd(); err != nil { | ||
eprintf(true, "%v\n", err) | ||
os.Exit(-1) | ||
} | ||
|
||
repairMain(c.Context()) | ||
}, | ||
} | ||
|
||
func init() { | ||
setFlagOpts(repairCmd) | ||
|
||
addDryRunFlag(repairCmd, "Repair drives with no modify mode") | ||
repairCmd.PersistentFlags().BoolVar(&forceFlag, "force", forceFlag, "Force log zeroing") | ||
repairCmd.PersistentFlags().BoolVar(&disablePrefetchFlag, "disable-prefetch", disablePrefetchFlag, "Disable prefetching of inode and directory blocks") | ||
} | ||
|
||
func validateRepairCmd() error { | ||
if err := validateDriveIDArgs(); err != nil { | ||
return err | ||
} | ||
|
||
if len(driveIDArgs) == 0 { | ||
return errors.New("no drive provided to repair") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func repairMain(ctx context.Context) { | ||
_, err := adminClient.Repair( | ||
ctx, | ||
admin.RepairArgs{ | ||
DriveIDs: driveIDSelectors, | ||
DryRun: dryRunFlag, | ||
ForceFlag: forceFlag, | ||
DisablePrefetchFlag: disablePrefetchFlag, | ||
}, | ||
logFunc, | ||
) | ||
if err != nil { | ||
eprintf(!errors.Is(err, admin.ErrNoMatchingResourcesFound), "%v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.