Skip to content

Commit

Permalink
PackageInstall: default SyncPeriod to 10 minutes (#387)
Browse files Browse the repository at this point in the history
* PackageInstall: default SyncPeriod to 10 minutes

* I never met a v1 that couldn't be synced every 10 minutes.
  • Loading branch information
joe-kimmel-vmw authored Oct 4, 2021
1 parent 1c27dd5 commit bad0a71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/packageinstall/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"fmt"
"sort"
"strings"
"time"

"github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
kcv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
pkgingv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/packaging/v1alpha1"
datapkgingv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apiserver/apis/datapackaging/v1alpha1"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/client/clientset/versioned/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand Down Expand Up @@ -40,7 +42,11 @@ func NewApp(existingApp *v1alpha1.App, pkgInstall *pkgingv1alpha1.PackageInstall
desiredApp.Namespace = pkgInstall.Namespace
desiredApp.Spec = *pkgVersion.Spec.Template.Spec
desiredApp.Spec.ServiceAccountName = pkgInstall.Spec.ServiceAccountName
desiredApp.Spec.SyncPeriod = pkgInstall.Spec.SyncPeriod
if pkgInstall.Spec.SyncPeriod == nil {
desiredApp.Spec.SyncPeriod = &metav1.Duration{Duration: time.Minute * 10}
} else {
desiredApp.Spec.SyncPeriod = pkgInstall.Spec.SyncPeriod
}
desiredApp.Spec.NoopDelete = pkgInstall.Spec.NoopDelete
desiredApp.Spec.Paused = pkgInstall.Spec.Paused
desiredApp.Spec.Canceled = pkgInstall.Spec.Canceled
Expand Down
12 changes: 12 additions & 0 deletions pkg/packageinstall/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package packageinstall_test
import (
"reflect"
"testing"
"time"

"github.com/ghodss/yaml"
"github.com/stretchr/testify/require"
Expand All @@ -16,6 +17,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// several tests below have no SyncPeriod set so they'll all use the same default.
var defaultSyncPeriod metav1.Duration = metav1.Duration{10 * time.Minute}

func TestAppExtYttPathsFromSecretNameAnn(t *testing.T) {
ipkg := &pkgingv1alpha1.PackageInstall{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -53,6 +57,7 @@ func TestAppExtYttPathsFromSecretNameAnn(t *testing.T) {

expectedApp := &kcv1alpha1.App{
Spec: kcv1alpha1.AppSpec{
SyncPeriod: &defaultSyncPeriod,
Template: []kcv1alpha1.AppTemplate{
// Helm template step is untouched
{HelmTemplate: &kcv1alpha1.AppTemplateHelmTemplate{}},
Expand Down Expand Up @@ -136,6 +141,7 @@ func TestAppExtYttDataValuesOverlaysAnn(t *testing.T) {

expectedApp := &kcv1alpha1.App{
Spec: kcv1alpha1.AppSpec{
SyncPeriod: &defaultSyncPeriod,
Template: []kcv1alpha1.AppTemplate{
{Ytt: &kcv1alpha1.AppTemplateYtt{
Inline: &kcv1alpha1.AppFetchInline{
Expand Down Expand Up @@ -205,6 +211,7 @@ func TestAppYttValues(t *testing.T) {

expectedApp := &kcv1alpha1.App{
Spec: kcv1alpha1.AppSpec{
SyncPeriod: &defaultSyncPeriod,
Template: []kcv1alpha1.AppTemplate{
{Ytt: &kcv1alpha1.AppTemplateYtt{
ValuesFrom: []kcv1alpha1.AppTemplateValuesSource{
Expand Down Expand Up @@ -273,6 +280,7 @@ func TestAppHelmTemplateValues(t *testing.T) {

expectedApp := &kcv1alpha1.App{
Spec: kcv1alpha1.AppSpec{
SyncPeriod: &defaultSyncPeriod,
Template: []kcv1alpha1.AppTemplate{
{HelmTemplate: &kcv1alpha1.AppTemplateHelmTemplate{
ValuesFrom: []kcv1alpha1.AppTemplateValuesSource{
Expand Down Expand Up @@ -381,6 +389,9 @@ func TestAppCustomFetchSecretNames(t *testing.T) {
"ext.packaging.carvel.dev/fetch-6-secret-name": "secret6-name",
},
},
Spec: pkgingv1alpha1.PackageInstallSpec{
SyncPeriod: &metav1.Duration{100 * time.Second},
},
}

pkgVersion := datapkgingv1alpha1.Package{
Expand Down Expand Up @@ -412,6 +423,7 @@ func TestAppCustomFetchSecretNames(t *testing.T) {

expectedApp := &kcv1alpha1.App{
Spec: kcv1alpha1.AppSpec{
SyncPeriod: &metav1.Duration{100 * time.Second},
Fetch: []kcv1alpha1.AppFetch{
{HelmChart: &kcv1alpha1.AppFetchHelmChart{ // 0
// no repository specified, so no secret set
Expand Down
2 changes: 1 addition & 1 deletion pkg/pkgrepository/package_repo_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ metadata:
}

if pkgRepository.Spec.SyncPeriod == nil {
desiredApp.Spec.SyncPeriod = &metav1.Duration{Duration: time.Minute * 5}
desiredApp.Spec.SyncPeriod = &metav1.Duration{Duration: time.Minute * 10}
} else {
desiredApp.Spec.SyncPeriod = pkgRepository.Spec.SyncPeriod
}
Expand Down

0 comments on commit bad0a71

Please sign in to comment.