Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracting the load/save logic into their own functions Updating commandline options for pruning graph Code review changes Adding items that are in both the To and From lists Go formatting Performing prune inside method with defer Returning error from saveUpgradeGraph() Post-rebase updates Small refactoring Fix klog version Convert to using set
- Loading branch information
1 parent
c2894de
commit 7012ece
Showing
3 changed files
with
211 additions
and
63 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,75 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
releasecontroller "github.com/openshift/release-controller/pkg/release-controller" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
kv1core "k8s.io/client-go/kubernetes/typed/core/v1" | ||
"k8s.io/klog" | ||
) | ||
|
||
func (c *Controller) PruneGraph(secretClient kv1core.SecretInterface, ns, name string, printOption string, confirm bool) error { | ||
stopCh := wait.NeverStop | ||
|
||
releasecontroller.LoadUpgradeGraph(c.graph, secretClient, ns, name, stopCh) | ||
|
||
imageStreams, err := c.releaseLister.ImageStreams(ns).List(labels.Everything()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var stableTagList []string | ||
|
||
for _, imageStream := range imageStreams { | ||
r, ok, err := releasecontroller.ReleaseDefinition(imageStream, c.parsedReleaseConfigCache, c.eventRecorder, *c.releaseLister) | ||
if err != nil || !ok { | ||
continue | ||
} | ||
if r.Config.As == releasecontroller.ReleaseConfigModeStable { | ||
for _, tag := range imageStream.Spec.Tags { | ||
stableTagList = append(stableTagList, tag.Name) | ||
} | ||
} | ||
} | ||
|
||
// To tags that are not present in the stable tags | ||
toMissingList := make([]string, 0, len(c.graph.To)) | ||
for tag := range c.graph.To { | ||
if !releasecontroller.StringSliceContains(stableTagList, tag) { | ||
toMissingList = append(toMissingList, tag) | ||
} | ||
} | ||
|
||
// From tags that are not present in the stable tags | ||
fromMissingList := make([]string, 0, len(c.graph.From)) | ||
for tag := range c.graph.From { | ||
if !releasecontroller.StringSliceContains(stableTagList, tag) { | ||
fromMissingList = append(fromMissingList, tag) | ||
} | ||
} | ||
|
||
// Combine the 2 lists into a set to eliminate duplicates | ||
pruneTagList := sets.NewString(append(toMissingList, fromMissingList...)...).UnsortedList() | ||
klog.V(2).Infof("Pruning %d/%d tags from release controller graph\n", len(pruneTagList), len(c.graph.To)) | ||
|
||
c.graph.PruneTags(pruneTagList) | ||
|
||
if confirm { | ||
buf := &bytes.Buffer{} | ||
err = releasecontroller.SaveUpgradeGraph(buf, c.graph, secretClient, ns, name) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
switch printOption { | ||
case releasecontroller.PruneGraphPrintDebug: | ||
c.graph.PrettyPrint() | ||
case releasecontroller.PruneGraphPrintSecret: | ||
c.graph.PrintSecretPayload() | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.