Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
srueg committed Apr 20, 2021
1 parent 14fa198 commit 4ceecc3
Show file tree
Hide file tree
Showing 16 changed files with 618 additions and 173 deletions.
7 changes: 4 additions & 3 deletions cmd/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"strings"

Expand All @@ -13,11 +14,11 @@ import (
)

// DeleteImages deletes a list of image tags
func DeleteImages(imageTags []string, imageName string, namespace string) {
func DeleteImages(ctx context.Context, imageTags []string, imageName string, namespace string) {
for _, inactiveTag := range imageTags {
log.Infof("Deleting %s/%s:%s", namespace, imageName, inactiveTag)

if err := openshift.DeleteImageStreamTag(namespace, openshift.BuildImageStreamTagName(imageName, inactiveTag)); err != nil {
if err := openshift.DeleteImageStreamTag(ctx, namespace, openshift.BuildImageStreamTagName(imageName, inactiveTag)); err != nil {
log.WithError(err).Errorf("Failed to delete %s/%s:%s", namespace, imageName, inactiveTag)
}
}
Expand Down Expand Up @@ -52,7 +53,7 @@ func addCommonFlagsForGit(cmd *cobra.Command, defaults *cfg.Configuration) {

// toListOptions converts "key=value"-labels to Kubernetes LabelSelector
func toListOptions(labels []string) metav1.ListOptions {
labelSelector := fmt.Sprintf(strings.Join(labels, ","))
labelSelector := fmt.Sprint(strings.Join(labels, ","))
return metav1.ListOptions{
LabelSelector: labelSelector,
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/configmaps.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cmd

import (
"context"
"fmt"
"strings"

"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/configmap"
"github.com/appuio/seiso/pkg/kubernetes"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"strings"
)

const (
Expand Down Expand Up @@ -63,6 +65,7 @@ func executeConfigMapCleanupCommand(cmd *cobra.Command, args []string) error {
return fmt.Errorf("cannot initiate kubernetes client: %w", err)
}

ctx := context.Background()
c := config.Resource
namespace := config.Namespace
service := configmap.NewConfigMapsService(
Expand All @@ -71,12 +74,12 @@ func executeConfigMapCleanupCommand(cmd *cobra.Command, args []string) error {
configmap.ServiceConfiguration{Batch: config.Log.Batch})

log.WithField("namespace", namespace).Debug("Getting ConfigMaps")
foundConfigMaps, err := service.List(toListOptions(c.Labels))
foundConfigMaps, err := service.List(ctx, toListOptions(c.Labels))
if err != nil {
return fmt.Errorf("could not retrieve ConfigMaps with labels '%s' for '%s': %w", c.Labels, namespace, err)
}

unusedConfigMaps, err := service.GetUnused(namespace, foundConfigMaps)
unusedConfigMaps, err := service.GetUnused(ctx, namespace, foundConfigMaps)
if err != nil {
return fmt.Errorf("could not retrieve unused config maps for '%s': %w", namespace, err)
}
Expand All @@ -86,7 +89,7 @@ func executeConfigMapCleanupCommand(cmd *cobra.Command, args []string) error {
filteredConfigMaps = service.FilterByMaxCount(filteredConfigMaps, config.History.Keep)

if config.Delete {
err := service.Delete(filteredConfigMaps)
err := service.Delete(ctx, filteredConfigMaps)
if err != nil {
return fmt.Errorf("could not delete ConfigMaps for '%s': %s", namespace, err)
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/history.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"context"
"fmt"

"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/cleanup"
"github.com/appuio/seiso/pkg/git"
Expand Down Expand Up @@ -56,9 +58,10 @@ func validateHistoryCommandInput(cmd *cobra.Command, args []string) (returnErr e
// ExecuteHistoryCleanupCommand executes the history cleanup command
func ExecuteHistoryCleanupCommand(cmd *cobra.Command, args []string) error {
c := config.History
ctx := context.Background()
namespace, imageName, _ := splitNamespaceAndImagestream(args[0])

imageStreamObjectTags, err := openshift.GetImageStreamTags(namespace, imageName)
imageStreamObjectTags, err := openshift.GetImageStreamTags(ctx, namespace, imageName)
if err != nil {
return fmt.Errorf("could not retrieve image stream '%s/%s': %w", namespace, imageName, err)
}
Expand All @@ -79,7 +82,7 @@ func ExecuteHistoryCleanupCommand(cmd *cobra.Command, args []string) error {
}
var matchingTags = cleanup.GetMatchingTags(&gitCandidates, &imageStreamTags, matchOption)

activeImageStreamTags, err := openshift.GetActiveImageStreamTags(namespace, imageName, matchingTags)
activeImageStreamTags, err := openshift.GetActiveImageStreamTags(ctx, namespace, imageName, matchingTags)
if err != nil {
return fmt.Errorf("could not retrieve active image stream tags for '%s/%s': %w", namespace, imageName, err)
}
Expand All @@ -94,7 +97,7 @@ func ExecuteHistoryCleanupCommand(cmd *cobra.Command, args []string) error {
return nil
}
if config.Delete {
DeleteImages(inactiveTags, imageName, namespace)
DeleteImages(ctx, inactiveTags, imageName, namespace)
} else {
log.Infof("Showing results for --commit-limit=%d and --keep=%d", config.Git.CommitLimit, c.Keep)
PrintImageTags(inactiveTags, imageName, namespace)
Expand Down
8 changes: 5 additions & 3 deletions cmd/orphans.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"regexp"
"time"
Expand Down Expand Up @@ -79,9 +80,10 @@ func validateOrphanCommandInput(cmd *cobra.Command, args []string) (returnErr er
// ExecuteOrphanCleanupCommand executes the orphan cleanup command
func ExecuteOrphanCleanupCommand(cmd *cobra.Command, args []string) error {
c := config.Orphan
ctx := context.Background()
namespace, imageName, _ := splitNamespaceAndImagestream(args[0])

allImageTags, err := openshift.GetImageStreamTags(namespace, imageName)
allImageTags, err := openshift.GetImageStreamTags(ctx, namespace, imageName)
if err != nil {
return fmt.Errorf("could not retrieve image stream '%v/%v': %w", namespace, imageName, err)
}
Expand All @@ -101,7 +103,7 @@ func ExecuteOrphanCleanupCommand(cmd *cobra.Command, args []string) error {
imageTagList := cleanup.FilterImageTagsByTime(&allImageTags, cutOffDateTime)
imageTagList = cleanup.FilterOrphanImageTags(&gitCandidates, &imageTagList, matchOption)
imageTagList = cleanup.FilterByRegex(&imageTagList, orphanIncludeRegex)
imageTagList, err = cleanup.FilterActiveImageTags(namespace, imageName, imageTagList, &imageTagList)
imageTagList, err = cleanup.FilterActiveImageTags(ctx, namespace, imageName, imageTagList, &imageTagList)
if err != nil {
return err
}
Expand All @@ -114,7 +116,7 @@ func ExecuteOrphanCleanupCommand(cmd *cobra.Command, args []string) error {
}

if config.Delete {
DeleteImages(imageTagList, imageName, namespace)
DeleteImages(ctx, imageTagList, imageName, namespace)
} else {
log.Infof("Showing results for --commit-limit=%d and --older-than=%s", config.Git.CommitLimit, c.OlderThan)
PrintImageTags(imageTagList, imageName, namespace)
Expand Down
11 changes: 7 additions & 4 deletions cmd/secrets.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cmd

import (
"context"
"fmt"
"strings"

"github.com/appuio/seiso/cfg"
"github.com/appuio/seiso/pkg/kubernetes"
"github.com/appuio/seiso/pkg/secret"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"strings"
)

const (
Expand Down Expand Up @@ -63,6 +65,7 @@ func executeSecretCleanupCommand(cmd *cobra.Command, args []string) error {
return fmt.Errorf("cannot initiate kubernetes client: %w", err)
}

ctx := context.Background()
c := config.Resource
namespace := config.Namespace
service := secret.NewSecretsService(
Expand All @@ -71,12 +74,12 @@ func executeSecretCleanupCommand(cmd *cobra.Command, args []string) error {
secret.ServiceConfiguration{Batch: config.Log.Batch})

log.WithField("namespace", namespace).Debug("Getting Secrets")
foundSecrets, err := service.List(toListOptions(c.Labels))
foundSecrets, err := service.List(ctx, toListOptions(c.Labels))
if err != nil {
return fmt.Errorf("could not retrieve Secrets with labels '%s' for '%s': %w", c.Labels, namespace, err)
}

unusedSecrets, err := service.GetUnused(namespace, foundSecrets)
unusedSecrets, err := service.GetUnused(ctx, namespace, foundSecrets)
if err != nil {
return fmt.Errorf("could not retrieve unused Secrets for '%s': %w", namespace, err)
}
Expand All @@ -87,7 +90,7 @@ func executeSecretCleanupCommand(cmd *cobra.Command, args []string) error {
filteredSecrets = service.FilterByMaxCount(filteredSecrets, config.History.Keep)

if config.Delete {
err := service.Delete(filteredSecrets)
err := service.Delete(ctx, filteredSecrets)
if err != nil {
return fmt.Errorf("could not delete Secrets for '%s': %s", namespace, err)
}
Expand Down
38 changes: 19 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
module github.com/appuio/seiso

go 1.15
go 1.16

require (
github.com/etdub/goparsetime v0.0.0-20160315173935-ea17b0ac3318 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/go-version v1.2.0
github.com/imdario/mergo v0.3.8 // indirect
github.com/json-iterator/go v1.1.8 // indirect
github.com/go-logr/logr v0.3.0 // indirect
github.com/googleapis/gnostic v0.5.1 // indirect
github.com/hashicorp/go-version v1.3.0
github.com/imdario/mergo v0.3.10 // indirect
github.com/karrick/tparse v2.4.2+incompatible
github.com/knadh/koanf v0.10.0
github.com/openshift/api v3.9.1-0.20190322043348-8741ff068a47+incompatible
github.com/openshift/client-go v0.0.0-20180830153425-431ec9a26e50
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.6
github.com/knadh/koanf v0.16.0
github.com/onsi/ginkgo v1.14.1 // indirect
github.com/onsi/gomega v1.10.2 // indirect
github.com/openshift/api v0.0.0-20210202165416-a9e731090f5e
github.com/openshift/client-go v0.0.0-20210112165513-ebc401615f47
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
github.com/thoas/go-funk v0.6.0
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
github.com/stretchr/testify v1.7.0
github.com/thoas/go-funk v0.8.0
google.golang.org/appengine v1.6.6 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
k8s.io/api v0.0.0-20180712090710-2d6f90ab1293
k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d
k8s.io/client-go v0.0.0-20180718001006-59698c7d9724
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29 // indirect
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/client-go v0.20.2
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 // indirect
)
Loading

0 comments on commit 4ceecc3

Please sign in to comment.