-
Notifications
You must be signed in to change notification settings - Fork 248
/
main.go
84 lines (69 loc) · 2.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"errors"
"flag"
"fmt"
"path"
"time"
"github.com/sirupsen/logrus"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"github.com/openshift/ci-tools/pkg/api/ocplifecycle"
"github.com/openshift/ci-tools/pkg/branchcuts/bumper"
cioperatorcfg "github.com/openshift/ci-tools/pkg/config"
)
const (
releaseJobsPath = "ci-operator/config/openshift/release"
)
type options struct {
curOCPVersion string
releaseRepoDir string
logLevel int
newIntervalValue int
}
func gatherOptions() (*options, error) {
var errs []error
o := &options{}
flag.StringVar(&o.curOCPVersion, "current-release", "", "Current OCP version")
flag.StringVar(&o.releaseRepoDir, "release-repo", "", "Path to 'openshift/release/ folder")
flag.IntVar(&o.newIntervalValue, "interval", 168, "New interval to set")
flag.IntVar(&o.logLevel, "log-level", int(logrus.DebugLevel), "Log level")
flag.Parse()
if _, err := ocplifecycle.ParseMajorMinor(o.curOCPVersion); o.curOCPVersion != "" && err != nil {
errs = append(errs, fmt.Errorf("error parsing current-release %s", o.curOCPVersion))
}
if o.newIntervalValue < 0 {
errs = append(errs, errors.New("error parsing interval: value is not a positive integer"))
}
if o.releaseRepoDir != "" {
if !path.IsAbs(o.releaseRepoDir) {
errs = append(errs, errors.New("error parsing release repo path: path has to be absolute"))
}
} else {
errs = append(errs, errors.New("error parsing release repo path: path is mandatory"))
}
return o, utilerrors.NewAggregate(errs)
}
func main() {
o, err := gatherOptions()
if err != nil {
logrus.WithError(err).Fatal("failed to gather options")
}
logrus.SetLevel(logrus.Level(o.logLevel))
logrus.Debugf("using options %+v", o)
if err := reconcile(time.Now(), o); err != nil {
logrus.WithError(err).Fatal("failed to reconcile the status")
}
logrus.Info("status reconciled")
}
func reconcile(now time.Time, o *options) error {
logrus.Debugf("using options %+v", o)
releaseJobsDir := path.Join(o.releaseRepoDir, releaseJobsPath)
b, err := bumper.NewGeneratedReleaseGatingJobsBumper(o.curOCPVersion, releaseJobsDir, o.newIntervalValue)
if err != nil {
return fmt.Errorf("new bumper: %w", err)
}
if err := bumper.Bump[*cioperatorcfg.DataWithInfo](b, &bumper.BumpingOptions{}); err != nil {
return fmt.Errorf("bumper: %w", err)
}
return nil
}