Skip to content

Commit

Permalink
adds an onclustertesting binary to help with setup / teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesesashimi committed Aug 15, 2023
1 parent 8001633 commit 6346406
Show file tree
Hide file tree
Showing 11 changed files with 1,303 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/onclustertesting/clearstatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/openshift/machine-config-operator/test/framework"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
)

var (
clearStatusCmd = &cobra.Command{
Use: "clear-build-status",
Short: "Tears down the pool for on-cluster build testing",
Long: "",
Run: runClearStatusCmd,
}

clearStatusOpts struct {
poolName string
}
)

func init() {
rootCmd.AddCommand(clearStatusCmd)
clearStatusCmd.PersistentFlags().StringVar(&clearStatusOpts.poolName, "pool", defaultLayeredPoolName, "Pool name to clear build status on")
}

func runClearStatusCmd(_ *cobra.Command, _ []string) {
common(clearStatusOpts)

if clearStatusOpts.poolName == "" {
klog.Fatalln("No pool name provided!")
}

failOnError(clearBuildStatusesOnPool(framework.NewClientSet(""), clearStatusOpts.poolName))
}
56 changes: 56 additions & 0 deletions cmd/onclustertesting/extract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"github.com/openshift/machine-config-operator/test/framework"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
)

var (
extractCmd = &cobra.Command{
Use: "extract",
Short: "Extracts the Dockerfile and MachineConfig from an on-cluster build",
Long: "",
Run: runExtractCmd,
}

extractOpts struct {
poolName string
machineConfig string
targetDir string
noConfigMaps bool
}
)

func init() {
rootCmd.AddCommand(extractCmd)
extractCmd.PersistentFlags().StringVar(&extractOpts.poolName, "pool", defaultLayeredPoolName, "Pool name to extract")
extractCmd.PersistentFlags().StringVar(&extractOpts.machineConfig, "machineconfig", "", "MachineConfig name to extract")
extractCmd.PersistentFlags().StringVar(&extractOpts.targetDir, "dir", "", "Dir to store extract build objects")
}

func runExtractCmd(_ *cobra.Command, _ []string) {
common(extractOpts)

if extractOpts.poolName == "" && extractOpts.machineConfig == "" {
klog.Fatalln("No pool name or MachineConfig name provided!")
}

if extractOpts.poolName != "" && extractOpts.machineConfig != "" {
klog.Fatalln("Either pool name or MachineConfig must be provided. Not both!")
}

targetDir := getDir(extractOpts.targetDir)

cs := framework.NewClientSet("")

if extractOpts.machineConfig != "" {
failOnError(extractBuildObjectsForRenderedMC(cs, extractOpts.machineConfig, targetDir))
return
}

if extractOpts.poolName != "" {
failOnError(extractBuildObjectsForTargetPool(cs, extractOpts.poolName, targetDir))
return
}
}
Loading

0 comments on commit 6346406

Please sign in to comment.