Skip to content

Commit

Permalink
GetAvailableVersions => ListAvailableVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Jan 19, 2022
1 parent ed49bd7 commit 5b639fc
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 109 deletions.
8 changes: 4 additions & 4 deletions pkg/helm/watcher/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type Cache interface {
// GetProfileValues will try and find a specific values file for the given profileName and profileVersion. Returns an
// error if said version is not found.
GetProfileValues(ctx context.Context, helmRepoNamespace, helmRepoName, profileName, profileVersion string) ([]byte, error)
// GetAvailableVersionsForProfile returns all stored available versions for a profile.
GetAvailableVersionsForProfile(ctx context.Context, helmRepoNamespace, helmRepoName, profileName string) ([]string, error)
// ListAvailableVersionsForProfile returns all stored available versions for a profile.
ListAvailableVersionsForProfile(ctx context.Context, helmRepoNamespace, helmRepoName, profileName string) ([]string, error)
}

// Data is explicit data for a specific profile including values.
Expand Down Expand Up @@ -160,8 +160,8 @@ func (c *ProfileCache) ListProfiles(ctx context.Context, helmRepoNamespace, helm
return result, nil
}

// GetAvailableVersionsForProfile returns all stored available versions for a profile.
func (c *ProfileCache) GetAvailableVersionsForProfile(ctx context.Context, helmRepoNamespace, helmRepoName, profileName string) ([]string, error) {
// ListAvailableVersionsForProfile returns all stored available versions for a profile.
func (c *ProfileCache) ListAvailableVersionsForProfile(ctx context.Context, helmRepoNamespace, helmRepoName, profileName string) ([]string, error) {
// Because the folders of versions are only stored when there are values for a version
// we, instead, look in the profiles.yaml file for available versions.
var result []string
Expand Down
20 changes: 10 additions & 10 deletions pkg/helm/watcher/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestDeleteExistingData(t *testing.T) {
assert.ErrorIs(t, err, os.ErrNotExist)
}

func TestGetAvailableVersionsForProfile(t *testing.T) {
func TestListAvailableVersionsForProfile(t *testing.T) {
profileCache, _ := setupCache(t)
data := Data{
Profiles: []*pb.Profile{profile1},
Expand All @@ -134,19 +134,19 @@ func TestGetAvailableVersionsForProfile(t *testing.T) {
},
}
assert.NoError(t, profileCache.Put(context.Background(), helmNamespace, helmName, data), "put call from cache should have worked")
versions, err := profileCache.GetAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, profile1.Name)
versions, err := profileCache.ListAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, profile1.Name)
assert.NoError(t, err)
assert.Equal(t, profile1.AvailableVersions, versions)
}

func TestGetAvailableVersionsForProfileNoCachedData(t *testing.T) {
func TestListAvailableVersionsForProfileNoCachedData(t *testing.T) {
profileCache, _ := setupCache(t)
versions, err := profileCache.GetAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, profile1.Name)
versions, err := profileCache.ListAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, profile1.Name)
assert.NoError(t, err)
assert.Nil(t, versions)
}

func TestGetAvailableVersionsForProfileNameNotFound(t *testing.T) {
func TestListAvailableVersionsForProfileNameNotFound(t *testing.T) {
profileCache, _ := setupCache(t)
data := Data{
Profiles: []*pb.Profile{profile1},
Expand All @@ -155,11 +155,11 @@ func TestGetAvailableVersionsForProfileNameNotFound(t *testing.T) {
},
}
assert.NoError(t, profileCache.Put(context.Background(), helmNamespace, helmName, data), "put call from cache should have worked")
_, err := profileCache.GetAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, "notfound")
_, err := profileCache.ListAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, "notfound")
assert.EqualError(t, err, "profile with name notfound not found in cached profiles")
}

func TestGetAvailableVersionsForProfileInvalidYamlData(t *testing.T) {
func TestListAvailableVersionsForProfileInvalidYamlData(t *testing.T) {
profileCache, dir := setupCache(t)
data := Data{
Profiles: []*pb.Profile{profile1},
Expand All @@ -169,7 +169,7 @@ func TestGetAvailableVersionsForProfileInvalidYamlData(t *testing.T) {
}
assert.NoError(t, profileCache.Put(context.Background(), helmNamespace, helmName, data), "put call from cache should have worked")
assert.NoError(t, os.WriteFile(filepath.Join(dir, helmNamespace, helmName, profileFilename), []byte("empty"), 0700))
_, err := profileCache.GetAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, profile1.Name)
_, err := profileCache.ListAvailableVersionsForProfile(context.Background(), helmNamespace, helmName, profile1.Name)
assert.EqualError(t, err, "failed to unmarshal profiles data: error unmarshaling JSON: json: cannot unmarshal string into Go value of type []*profiles.Profile")
}

Expand Down Expand Up @@ -197,9 +197,9 @@ func TestDeleteFailedLock(t *testing.T) {
assert.EqualError(t, err, "unable to read lock file cache.lock: open nope/cache.lock: no such file or directory")
}

func TestTestGetAvailableVersionsForProfileFailedLock(t *testing.T) {
func TestTestListAvailableVersionsForProfileFailedLock(t *testing.T) {
profileCache := &ProfileCache{cacheLocation: "nope"}
_, err := profileCache.GetAvailableVersionsForProfile(context.Background(), "", "", "")
_, err := profileCache.ListAvailableVersionsForProfile(context.Background(), "", "", "")
assert.EqualError(t, err, "unable to read lock file cache.lock: open nope/cache.lock: no such file or directory")
}

Expand Down
168 changes: 84 additions & 84 deletions pkg/helm/watcher/cache/cachefakes/fake_cache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/helm/watcher/controller/helm_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *HelmWatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request)
log.Error(err, "checking for new versions failed")
} else if v != "" {
log.Info("sending notification event for new version", "version", v)
r.event(ctx, &repository, repository.Status.Artifact.Revision, "info", fmt.Sprintf("New version available for profile %s with version %s", chart.Name, v))
r.sendEvent(ctx, &repository, repository.Status.Artifact.Revision, "info", fmt.Sprintf("New version available for profile %s with version %s", chart.Name, v))
}

for _, v := range chart.AvailableVersions {
Expand Down Expand Up @@ -159,8 +159,8 @@ func (r *HelmWatcherReconciler) reconcileDelete(ctx context.Context, repository
return ctrl.Result{}, nil
}

// event emits a Kubernetes event and forwards the event to notification controller if configured.
func (r *HelmWatcherReconciler) event(ctx context.Context, hr *sourcev1.HelmRepository, revision, severity, msg string) {
// sendEvent emits a Kubernetes event and forwards the event to notification controller if configured.
func (r *HelmWatcherReconciler) sendEvent(ctx context.Context, hr *sourcev1.HelmRepository, revision, severity, msg string) {
log := logr.FromContextOrDiscard(ctx)

if r.ExternalEventRecorder == nil {
Expand Down Expand Up @@ -188,7 +188,7 @@ func (r *HelmWatcherReconciler) event(ctx context.Context, hr *sourcev1.HelmRepo
// compared to what's already stored in the cache. It returns the LATEST version which is greater than
// the last version that was stored.
func (r *HelmWatcherReconciler) checkForNewVersion(ctx context.Context, chart *pb.Profile) (string, error) {
versions, err := r.Cache.GetAvailableVersionsForProfile(ctx, chart.GetHelmRepository().GetNamespace(), chart.GetHelmRepository().GetName(), chart.Name)
versions, err := r.Cache.ListAvailableVersionsForProfile(ctx, chart.GetHelmRepository().GetNamespace(), chart.GetHelmRepository().GetName(), chart.Name)
if err != nil {
return "", err
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/helm/watcher/controller/helm_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestReconcileUpdateReturnsError(t *testing.T) {

func TestNotifyForGreaterVersion(t *testing.T) {
reconciler, fakeCache, _, fakeEventRecorder := setupReconcileAndFakes(repo1)
fakeCache.GetAvailableVersionsForProfileReturns([]string{"0.0.0"}, nil)
fakeCache.ListAvailableVersionsForProfileReturns([]string{"0.0.0"}, nil)

_, err := reconciler.Reconcile(context.Background(), ctrl.Request{
NamespacedName: types.NamespacedName{
Expand All @@ -238,7 +238,7 @@ func TestNotifyForGreaterVersion(t *testing.T) {

func TestDoNotNotifyForLesserOrEqualVersion(t *testing.T) {
reconciler, fakeCache, fakeRepoManager, fakeEventRecorder := setupReconcileAndFakes(repo1)
fakeCache.GetAvailableVersionsForProfileReturns([]string{"0.0.1"}, nil)
fakeCache.ListAvailableVersionsForProfileReturns([]string{"0.0.1"}, nil)
fakeRepoManager.ListChartsReturns([]*pb.Profile{profile1}, nil)

_, err := reconciler.Reconcile(context.Background(), ctrl.Request{
Expand All @@ -251,9 +251,9 @@ func TestDoNotNotifyForLesserOrEqualVersion(t *testing.T) {
assert.Zero(t, fakeEventRecorder.EventfCallCount())
}

func TestNotifyForGreaterVersionGetAvailableVersionsReturnsErrorIsSkipped(t *testing.T) {
func TestNotifyForGreaterVersionListAvailableVersionsReturnsErrorIsSkipped(t *testing.T) {
reconciler, fakeCache, _, _ := setupReconcileAndFakes()
fakeCache.GetAvailableVersionsForProfileReturns(nil, errors.New("nope"))
fakeCache.ListAvailableVersionsForProfileReturns(nil, errors.New("nope"))

_, err := reconciler.Reconcile(context.Background(), ctrl.Request{
NamespacedName: types.NamespacedName{
Expand All @@ -264,9 +264,9 @@ func TestNotifyForGreaterVersionGetAvailableVersionsReturnsErrorIsSkipped(t *tes
assert.NoError(t, err)
}

func TestNotifyForGreaterVersionGetAvailableVersionsReturnsHigherVersion(t *testing.T) {
func TestNotifyForGreaterVersionListAvailableVersionsReturnsHigherVersion(t *testing.T) {
reconciler, fakeCache, fakeRepoManager, fakeEventRecorder := setupReconcileAndFakes()
fakeCache.GetAvailableVersionsForProfileReturns([]string{"0.0.1"}, nil)
fakeCache.ListAvailableVersionsForProfileReturns([]string{"0.0.1"}, nil)
fakeRepoManager.ListChartsReturns([]*pb.Profile{profile1}, nil)

_, err := reconciler.Reconcile(context.Background(), ctrl.Request{
Expand All @@ -281,7 +281,7 @@ func TestNotifyForGreaterVersionGetAvailableVersionsReturnsHigherVersion(t *test

func TestNotifyForGreaterVersionEventSenderFailureIsIgnored(t *testing.T) {
reconciler, fakeCache, _, fakeEventRecorder := setupReconcileAndFakes()
fakeCache.GetAvailableVersionsForProfileReturns([]string{"0.0.0"}, nil)
fakeCache.ListAvailableVersionsForProfileReturns([]string{"0.0.0"}, nil)
fakeEventRecorder.EventfReturns(errors.New("nope"))

_, err := reconciler.Reconcile(context.Background(), ctrl.Request{
Expand Down

0 comments on commit 5b639fc

Please sign in to comment.