-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tasks and flows in OBCluster package (#249)
- Loading branch information
Showing
68 changed files
with
3,316 additions
and
3,057 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
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,102 @@ | ||
/* | ||
Copyright (c) 2023 OceanBase | ||
ob-operator is licensed under Mulan PSL v2. | ||
You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
You may obtain a copy of Mulan PSL v2 at: | ||
http://license.coscl.org.cn/MulanPSL2 | ||
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"go/ast" | ||
"go/parser" | ||
"go/token" | ||
"log" | ||
"os" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
const genTemplate = `// Code generated by go generate; DO NOT EDIT. | ||
package {{.PackageName}} | ||
func init() { | ||
{{- range .Tasks }} | ||
taskMap.Register(t{{.}}, {{.}}) | ||
{{- end }} | ||
} | ||
` | ||
|
||
type Task string | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
log.Fatalf("Usage: %s <source_file>", os.Args[0]) | ||
} | ||
sourceFile := os.Args[1] | ||
|
||
fset := token.NewFileSet() | ||
node, err := parser.ParseFile(fset, sourceFile, nil, 0) | ||
if err != nil { | ||
log.Fatalf("Failed to parse source file: %v", err) | ||
} | ||
|
||
taskFuncs := []Task{} | ||
ast.Inspect(node, func(n ast.Node) bool { | ||
fn, ok := n.(*ast.FuncDecl) | ||
if !ok { | ||
return true | ||
} | ||
// Get return type of function and check whether it is a func(resource T) TaskError | ||
if len(fn.Type.Params.List) == 1 && len(fn.Type.Results.List) == 1 { | ||
if strings.HasSuffix(exprToString(fn.Type.Results.List[0].Type), "TaskError") { | ||
taskFuncs = append(taskFuncs, Task(fn.Name.Name)) | ||
} | ||
} | ||
|
||
return true | ||
}) | ||
|
||
tmpl, err := template.New("registration").Parse(genTemplate) | ||
if err != nil { | ||
log.Fatalf("Failed to parse template: %v", err) | ||
} | ||
|
||
outputFile := sourceFile[:len(sourceFile)-3] + "_gen.go" | ||
|
||
f, err := os.Create(outputFile) | ||
if err != nil { | ||
log.Fatalf("Failed to create output file: %v", err) | ||
} | ||
defer f.Close() | ||
|
||
err = tmpl.Execute(f, struct { | ||
PackageName string | ||
Tasks []Task | ||
}{ | ||
PackageName: node.Name.Name, | ||
Tasks: taskFuncs, | ||
}) | ||
if err != nil { | ||
log.Printf("Failed to execute template: %v", err) | ||
} | ||
} | ||
|
||
func exprToString(expr ast.Expr) string { | ||
switch e := expr.(type) { | ||
case *ast.Ident: | ||
return e.Name | ||
case *ast.SelectorExpr: | ||
return exprToString(e.X) + "." + e.Sel.Name | ||
case *ast.StarExpr: | ||
return "*" + exprToString(e.X) | ||
default: | ||
return fmt.Sprintf("unknown(%T)", e) | ||
} | ||
} |
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,36 @@ | ||
/* | ||
Copyright (c) 2023 OceanBase | ||
ob-operator is licensed under Mulan PSL v2. | ||
You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
You may obtain a copy of Mulan PSL v2 at: | ||
http://license.coscl.org.cn/MulanPSL2 | ||
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package oceanbase | ||
|
||
const ( | ||
AnnotationCalicoValidate = "cni.projectcalico.org/podIP" | ||
AnnotationCalicoIpAddrs = "cni.projectcalico.org/ipAddrs" | ||
) | ||
|
||
const ( | ||
AnnotationsIndependentPVCLifecycle = "oceanbase.oceanbase.com/independent-pvc-lifecycle" | ||
AnnotationsSinglePVC = "oceanbase.oceanbase.com/single-pvc" | ||
AnnotationsMode = "oceanbase.oceanbase.com/mode" | ||
AnnotationsSourceClusterAddress = "oceanbase.oceanbase.com/source-cluster-address" | ||
AnnotationsIgnoreDeletion = "oceanbase.oceanbase.com/ignore-deletion" | ||
) | ||
|
||
const ( | ||
ModeStandalone = "standalone" | ||
ModeService = "service" | ||
) | ||
|
||
const ( | ||
CNICalico = "calico" | ||
CNIUnknown = "unknown" | ||
) |
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
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,38 @@ | ||
/* | ||
Copyright (c) 2023 OceanBase | ||
ob-operator is licensed under Mulan PSL v2. | ||
You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
You may obtain a copy of Mulan PSL v2 at: | ||
http://license.coscl.org.cn/MulanPSL2 | ||
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package oceanbase | ||
|
||
import "k8s.io/apimachinery/pkg/api/resource" | ||
|
||
const ( | ||
DefaultDiskExpandPercent = 10 | ||
DefaultLogPercent = 80 | ||
InitialDataDiskUsePercent = 20 | ||
DefaultDiskUsePercent = 95 | ||
DefaultMemoryLimitPercent = 90 | ||
GigaConverter = 1 << 30 | ||
MegaConverter = 1 << 20 | ||
) | ||
|
||
const ( | ||
DefaultMemoryLimitSize = "0M" | ||
DefaultDatafileMaxSize = "0M" | ||
DefaultDatafileNextSize = "1G" | ||
) | ||
|
||
var ( | ||
MinMemorySize = resource.MustParse("8Gi") | ||
MinDataDiskSize = resource.MustParse("30Gi") | ||
MinRedoLogDiskSize = resource.MustParse("30Gi") | ||
MinLogDiskSize = resource.MustParse("10Gi") | ||
) |
Oops, something went wrong.