Files
kubevela/hack/crd/dispatch/dispatch.go
wyike 4eb33e9239 split out oam-spec v0.2 charts (#1842)
* WIP disable oam related controller and webhok

change velue

fix spell error

change namespace

add e2e for oam-runtime

fix charts hack

fix e2e definition namespace

fix diasble contains list

fix e2e-test

* disable components handler

* fix flaky ac test

add every definition in oam-runtime-system namespace

* upload ac e2e-test

replace files

fix upload reports

* more wait time
2021-07-01 16:32:01 +08:00

93 lines
2.2 KiB
Go

/*
Copyright 2021 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)
var (
common = map[string]bool{"workloaddefinitions": true, "traitdefinitions": true, "scopedefinitions": true, "healthscopes": true,
"manualscalertraits": true, "containerizedworkloads": true}
oldCRD = map[string]bool{"components": true, "applicationconfigurations": true}
)
func main() {
var dir string
var oldDir string
var newDir string
if len(os.Args) > 2 {
dir = os.Args[1]
newDir = os.Args[2]
oldDir = os.Args[3]
} else {
log.Fatal(fmt.Errorf("not enough args"))
}
writeOld := func(fileName string, data []byte) {
pathOld := fmt.Sprintf("%s/%s", oldDir, fileName)
/* #nosec */
if err := ioutil.WriteFile(pathOld, data, 0644); err != nil {
log.Fatal(err)
}
}
writeNew := func(fileName string, data []byte) {
pathNew := fmt.Sprintf("%s/%s", newDir, fileName)
/* #nosec */
if err := ioutil.WriteFile(pathNew, data, 0644); err != nil {
log.Fatal(err)
}
}
err := filepath.Walk(dir, func(path string, info os.FileInfo, _ error) error {
if info.IsDir() {
return nil
}
resourceName := extractMainInfo(info.Name())
/* #nosec */
data, err := ioutil.ReadFile(path)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to read file", err)
return err
}
if oldCRD[resourceName] {
writeOld(info.Name(), data)
return nil
}
if common[resourceName] {
writeOld(info.Name(), data)
}
writeNew(info.Name(), data)
return nil
})
if err != nil {
log.Fatal(err)
}
log.Println("complete crd files dispatch")
}
func extractMainInfo(fileName string) string {
return strings.Split(strings.Split(fileName, "_")[1], ".")[0]
}