Skip to content

Commit

Permalink
WIP: release-gating jobs mgr: steps 1, 2
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-gemoli committed May 30, 2022
1 parent c09e588 commit 043f645
Show file tree
Hide file tree
Showing 38 changed files with 2,224 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/branchingconfigmanagers/docs/RELEASE-JOBS-COMMON.md
@@ -0,0 +1,5 @@
## Notes no how to specify paths
Every path specified below is intended to be an absolute path:
- BAD: `my/relative/path`
- GOOD: `/my/nice/absolute/path/to/config.yaml`
- ALSO-GOOD: `/my/nice/absolute/path/to/a/dir`
@@ -0,0 +1 @@
generated-release-gating-jobs
@@ -0,0 +1,7 @@
build:
go build ./...
.PHONY: build

clean:
go clean ./...
.PHONY: clean
@@ -0,0 +1,35 @@
# Generated release gating jobs manager
This manager attempts to automatize step (2.) of "[Few weeks before code freeze](https://docs.google.com/document/d/19kxmzXFnXrbLChZXBfxy68mCYg06j3qT93VF23wepog/edit#heading=h.r9xn02r1cyfn)" phase.

## Usage
Check [Notes no how to specify paths](../docs/RELEASE-JOBS-COMMON.md#notes-no-how-to-specify-paths) out first.

The `--lifecycle-config` switch is always mandatory and it has to point to a valid `ocplifecycle.yaml` config file.

The `--release-repo-path` has to point to the `openshift/release` folder.
When is specified and no others configurations are provided, the manager defaults `--release-gating` dir to `./ci-operator/config/openshift/release`

The previous path is relative to `--release-repo-path`

### Example 1
```sh
OCP_LIFECYCLE_CONFIG_FULLPATH="/full/path/to/ocplifecycle.yaml"
RELEASE_PROJECT_FULLPATH="/full/path/to/release/project"
$ ./generated-release-gating-jobs \
--lifecycle-config "$OCP_LIFECYCLE_CONFIG_FULLPATH" \
--release-repo-path "$RELEASE_PROJECT_FULLPATH"
```

Alternatively release-gatings jobs path can be overridden:

### Example 2
```sh
OCP_LIFECYCLE_CONFIG_FULLPATH="/full/path/to/ocplifecycle.yaml"
RELEASE_GATING_JOBS_DIR_FULLPATH="/full/path/to/release/gating/jobs/dir"
$ ./generated-release-gating-jobs \
--lifecycle-config "$OCP_LIFECYCLE_CONFIG_FULLPATH" \
--release-jobs "$RELEASE_GATING_JOBS_DIR_FULLPATH"
```

## Makefile
Run `make integration-tests` to launch integration tests.
158 changes: 158 additions & 0 deletions cmd/branchingconfigmanagers/generated-release-gating-jobs/main.go
@@ -0,0 +1,158 @@
package main

import (
"errors"
"flag"
"fmt"
"os"
"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"
mgr "github.com/openshift/ci-tools/pkg/branchcuts/config-manager"
cioperatorcfg "github.com/openshift/ci-tools/pkg/config"
)

const (
optsParsingErrorExitStatus = 1
reconcileErrorExitStatus = 2
releaseJobsPath = "ci-operator/config/openshift/release"
howManyDaysBefore = 14
lifecycleConfigFilePathDefaultPath = ""
)

type options struct {
curOCPVersion string
futureOCPVersion string
releaseJobsDir string
releaseRepoDir string
outDir string
lifecycleConfigFilePath string
logLevel int
newIntervalValue int
}

func (o *options) tryOverrideOCPVersions(curVersion, futureVersion string) {
if o.curOCPVersion == "" {
o.curOCPVersion = curVersion
}
if o.futureOCPVersion == "" {
o.futureOCPVersion = futureVersion
}
}

func (o *options) adjustPaths() error {
if o.releaseRepoDir != "" {
if !path.IsAbs(o.releaseRepoDir) {
return errors.New("release-repo-path path has to be absolute")
}

if path.IsAbs(o.releaseJobsDir) {
return errors.New("release-jobs path can't be absolute when release-jobs is specified")
}

o.releaseJobsDir = path.Join(o.releaseRepoDir, o.releaseJobsDir)
}
return nil
}

func gatherOptions() (*options, error) {
var errs []error
o := &options{}
flag.StringVar(&o.curOCPVersion, "current-release", "", "Current OCP version")
flag.StringVar(&o.futureOCPVersion, "future-release", "", "Next OCP version")
flag.StringVar(&o.releaseJobsDir, "release-jobs", releaseJobsPath, "Path to release-gating jobs .yaml files")
flag.StringVar(&o.releaseRepoDir, "release-repo-path", "", "Path to 'openshift/release/ folder")
flag.StringVar(&o.outDir, "out", "", "Output directory. Default to --release-jobs dir")
flag.StringVar(&o.lifecycleConfigFilePath, "lifecycle-config", lifecycleConfigFilePathDefaultPath, "Path to the lifecycle config file")
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 _, err := ocplifecycle.ParseMajorMinor(o.futureOCPVersion); o.futureOCPVersion != "" && err != nil {
errs = append(errs, fmt.Errorf("error parsing future-release %s", o.futureOCPVersion))
}

if o.newIntervalValue < 0 {
errs = append(errs, errors.New("error parsing interval: value is not a positive integer"))
}

if o.lifecycleConfigFilePath == "" {
errs = append(errs, errors.New("lifecycle-config is mandatory"))
}
if !path.IsAbs(o.lifecycleConfigFilePath) {
errs = append(errs, errors.New("lifecycle-config path is not absolute"))
}

if o.outDir != "" && !path.IsAbs(o.outDir) {
errs = append(errs, errors.New("out path is not absolute"))
}

return o, utilerrors.NewAggregate(errs)
}

func main() {
o, err := gatherOptions()
if err != nil {
logrus.WithError(err).Error("failed to gather options")
os.Exit(optsParsingErrorExitStatus)
}

if err = o.adjustPaths(); err != nil {
logrus.WithError(err).Error("failed to gather options")
os.Exit(optsParsingErrorExitStatus)
}

logrus.SetLevel(logrus.Level(o.logLevel))
logrus.Debugf("using options %+v", o)

recStatus, err := reconcile(time.Now(), o)
switch recStatus {
case mgr.ReconcileOk:
logrus.Info("status reconciled")
default:
logrus.WithError(err).Error("failed to reconcile the status")
os.Exit(reconcileErrorExitStatus)
}
}

func reconcile(now time.Time, o *options) (mgr.ReconcileStatus, error) {
lifecycleConfig, err := ocplifecycle.LoadConfig(o.lifecycleConfigFilePath)
if err != nil {
return mgr.ReconcileErr, fmt.Errorf("OCP Lifecycle load: %w", err)
}

ocpLifecycle := ocplifecycle.NewOCPCodeFreezeLifecycle(&lifecycleConfig, now)

if !ocpLifecycle.IsBeforeCodeFreeze(howManyDaysBefore) {
return mgr.ReconcileSkipped, nil
}

currentVersion, futureVersion, err := ocpLifecycle.GetOCPVersions()
if err != nil {
return mgr.ReconcileErr, fmt.Errorf("OCP Lifecycle versions: %w", err)
}

o.tryOverrideOCPVersions(currentVersion.GetVersion(), futureVersion.GetVersion())
logrus.Debugf("using options %+v", o)

b := bumper.NewGeneratedReleaseGatingJobsBumper(o.curOCPVersion, o.releaseJobsDir, o.newIntervalValue)
bumped, err := bumper.Bump[*cioperatorcfg.DataWithInfo](b, &bumper.BumpingOptions{
OutDir: o.outDir,
})

if !bumped || err != nil {
return mgr.ReconcileErr, fmt.Errorf("bumper: %w", err)
}

return mgr.ReconcileOk, nil
}
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
rpm-deps-mirroring-services
@@ -0,0 +1,7 @@
build:
go build ./...
.PHONY: build

clean:
go clean ./...
.PHONY: clean
35 changes: 35 additions & 0 deletions cmd/branchingconfigmanagers/rpm-deps-mirroring-services/README.md
@@ -0,0 +1,35 @@
# RPM dependencies mirroring services
This manager attempts to automatize step (1.) of "[Few weeks before code freeze](https://docs.google.com/document/d/19kxmzXFnXrbLChZXBfxy68mCYg06j3qT93VF23wepog/edit#heading=h.r9xn02r1cyfn)" phase.

## Usage
Check [Notes no how to specify paths](../docs/RELEASE-JOBS-COMMON.md#notes-no-how-to-specify-paths) out first.

The `--lifecycle-config` switch is always mandatory and it has to point to a valid `ocplifecycle.yaml` config file.

The `--release-repo-path` has to point to the `openshift/release` folder.
If not specified, the manager defaults `--mirroring-services` dir to `core-services/release-controller/_repos`

The previous paths are relative to `--release-repo-path`

### Example
```sh
OCP_LIFECYCLE_CONFIG_FULLPATH="/full/path/to/ocplifecycle.yaml"
RELEASE_PROJECT_FULLPATH="/full/path/to/release/project"
$ ./generated-release-gating-jobs \
--lifecycle-config "$OCP_LIFECYCLE_CONFIG_FULLPATH" \
--release-repo-path "$RELEASE_PROJECT_FULLPATH"
```

Alternatively `--mirroring-services` path can be overridden:

### Example
```sh
OCP_LIFECYCLE_CONFIG_FULLPATH="/full/path/to/ocplifecycle.yaml"
RPM_DEPS_MIRRORING_SERVICES_FULLPATH="/full/path/to/rpm/deps/mirroring/services"
$ ./generated-release-gating-jobs \
--lifecycle-config "$OCP_LIFECYCLE_CONFIG_FULLPATH" \
--mirroring-services "$RPM_DEPS_MIRRORING_SERVICES_FULLPATH"
```

## Makefile
Run `make integration-tests` to launch integration tests.

0 comments on commit 043f645

Please sign in to comment.