Skip to content

Commit

Permalink
Set DefaultMode for projected ProjectedVolumeSource (#413)
Browse files Browse the repository at this point in the history
This value is set server side for many resources, we can avoid churn by
setting it directly ourselves. 0644 is the default-default value.

Signed-off-by: Scott Andrews <scott@andrews.me>
  • Loading branch information
scothis authored May 14, 2024
1 parent b89d4d9 commit 6eb9d36
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
4 changes: 4 additions & 0 deletions controllers/servicebinding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"
dieappsv1 "reconciler.io/dies/apis/apps/v1"
diecorev1 "reconciler.io/dies/apis/core/v1"
diemetav1 "reconciler.io/dies/apis/meta/v1"
Expand All @@ -48,6 +49,7 @@ import (
"github.com/servicebinding/runtime/controllers"
dieservicebindingv1 "github.com/servicebinding/runtime/dies/v1"
"github.com/servicebinding/runtime/lifecycle"
"github.com/servicebinding/runtime/projector"
)

func TestServiceBindingReconciler(t *testing.T) {
Expand Down Expand Up @@ -127,6 +129,7 @@ func TestServiceBindingReconciler(t *testing.T) {
})
d.VolumeDie(fmt.Sprintf("servicebinding-%s", uid), func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.SourcesDie(
diecorev1.VolumeProjectionBlank.
SecretDie(func(d *diecorev1.SecretProjectionDie) {
Expand Down Expand Up @@ -936,6 +939,7 @@ func TestProjectBinding(t *testing.T) {
})
d.VolumeDie(fmt.Sprintf("servicebinding-%s", uid), func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.SourcesDie(
diecorev1.VolumeProjectionBlank.
SecretDie(func(d *diecorev1.SecretProjectionDie) {
Expand Down
5 changes: 5 additions & 0 deletions controllers/webhook_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/ptr"
dieadmissionv1 "reconciler.io/dies/apis/admission/v1"
dieadmissionregistrationv1 "reconciler.io/dies/apis/admissionregistration/v1"
dieappsv1 "reconciler.io/dies/apis/apps/v1"
Expand All @@ -54,6 +55,7 @@ import (
"github.com/servicebinding/runtime/controllers"
dieservicebindingv1 "github.com/servicebinding/runtime/dies/v1"
"github.com/servicebinding/runtime/lifecycle"
"github.com/servicebinding/runtime/projector"
"github.com/servicebinding/runtime/rbac"
)

Expand Down Expand Up @@ -298,6 +300,7 @@ func TestAdmissionProjectorWebhook(t *testing.T) {
})
d.VolumeDie(fmt.Sprintf("servicebinding-%s", bindingUID), func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.SourcesDie(
diecorev1.VolumeProjectionBlank.SecretDie(func(d *diecorev1.SecretProjectionDie) {
d.LocalObjectReference(corev1.LocalObjectReference{
Expand Down Expand Up @@ -379,6 +382,7 @@ func TestAdmissionProjectorWebhook(t *testing.T) {
map[string]interface{}{
"name": fmt.Sprintf("servicebinding-%s", bindingUID),
"projected": map[string]interface{}{
"defaultMode": float64(projector.VolumeDefaultMode),
"sources": []interface{}{
map[string]interface{}{
"secret": map[string]interface{}{
Expand Down Expand Up @@ -454,6 +458,7 @@ func TestAdmissionProjectorWebhook(t *testing.T) {
map[string]interface{}{
"name": fmt.Sprintf("servicebinding-%s", bindingUID),
"projected": map[string]interface{}{
"defaultMode": float64(projector.VolumeDefaultMode),
"sources": []interface{}{
map[string]interface{}{
"secret": map[string]interface{}{
Expand Down
4 changes: 2 additions & 2 deletions lifecycle/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
dieappsv1 "reconciler.io/dies/apis/apps/v1"
diecorev1 "reconciler.io/dies/apis/core/v1"
diemetav1 "reconciler.io/dies/apis/meta/v1"
Expand Down Expand Up @@ -303,7 +303,7 @@ func (p *mockProjector) IsProjected(ctx context.Context, binding *servicebinding

func makeHooks() (lifecycle.ServiceBindingHooks, *mock.Mock) {
m := &mock.Mock{}
i := pointer.Int(0)
i := ptr.To(0)
hooks := lifecycle.ServiceBindingHooks{
ResolverFactory: func(c client.Client) resolver.Resolver {
return resolver.New(c)
Expand Down
8 changes: 8 additions & 0 deletions lifecycle/vmware/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"
dieadmissionv1 "reconciler.io/dies/apis/admission/v1"
dieappsv1 "reconciler.io/dies/apis/apps/v1"
diecorev1 "reconciler.io/dies/apis/core/v1"
Expand All @@ -49,6 +50,7 @@ import (
dieservicebindingv1 "github.com/servicebinding/runtime/dies/v1"
"github.com/servicebinding/runtime/lifecycle"
"github.com/servicebinding/runtime/lifecycle/vmware"
"github.com/servicebinding/runtime/projector"
)

func TestMigrationHooks_Controller(t *testing.T) {
Expand Down Expand Up @@ -129,6 +131,7 @@ func TestMigrationHooks_Controller(t *testing.T) {
})
d.VolumeDie(fmt.Sprintf("servicebinding-%s", uid), func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.SourcesDie(
diecorev1.VolumeProjectionBlank.
SecretDie(func(d *diecorev1.SecretProjectionDie) {
Expand Down Expand Up @@ -197,6 +200,7 @@ func TestMigrationHooks_Controller(t *testing.T) {
})
d.VolumeDie("binding-4b2c350fb984fc36b6cf39515a2efced0fcb5053", func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.SourcesDie(
diecorev1.VolumeProjectionBlank.
SecretDie(func(d *diecorev1.SecretProjectionDie) {
Expand Down Expand Up @@ -363,6 +367,7 @@ func TestMigrationHooks_Controller(t *testing.T) {
})
d.VolumeDie("binding-4b2c350fb984fc36b6cf39515a2efced0fcb5053", func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.Sources(append(
d.DieRelease().Sources,
corev1.VolumeProjection{
Expand Down Expand Up @@ -452,6 +457,7 @@ func TestMigrationHooks_Controller(t *testing.T) {
})
d.VolumeDie("servicebinding-dde10100-d7b3-4cba-9430-51d60a8612a6", func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.Sources(append(
d.DieRelease().Sources,
corev1.VolumeProjection{
Expand Down Expand Up @@ -587,6 +593,7 @@ func TestMigrationHooks_Webhook(t *testing.T) {
})
d.VolumeDie(fmt.Sprintf("servicebinding-%s", uid), func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.SourcesDie(
diecorev1.VolumeProjectionBlank.
SecretDie(func(d *diecorev1.SecretProjectionDie) {
Expand Down Expand Up @@ -655,6 +662,7 @@ func TestMigrationHooks_Webhook(t *testing.T) {
})
d.VolumeDie("binding-4b2c350fb984fc36b6cf39515a2efced0fcb5053", func(d *diecorev1.VolumeDie) {
d.ProjectedDie(func(d *diecorev1.ProjectedVolumeSourceDie) {
d.DefaultMode(ptr.To(projector.VolumeDefaultMode))
d.SourcesDie(
diecorev1.VolumeProjectionBlank.
SecretDie(func(d *diecorev1.SecretProjectionDie) {
Expand Down
3 changes: 3 additions & 0 deletions projector/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"

servicebindingv1 "github.com/servicebinding/runtime/apis/v1"
)
Expand All @@ -42,6 +43,7 @@ const (
TypeAnnotationPrefix = Group + "/type-"
ProviderAnnotationPrefix = Group + "/provider-"
MappingAnnotationPrefix = Group + "/mapping-"
VolumeDefaultMode = int32(0644)
)

var _ ServiceBindingProjector = (*serviceBindingProjector)(nil)
Expand Down Expand Up @@ -205,6 +207,7 @@ func (p *serviceBindingProjector) projectVolume(binding *servicebindingv1.Servic
Name: p.volumeName(binding),
VolumeSource: corev1.VolumeSource{
Projected: &corev1.ProjectedVolumeSource{
DefaultMode: ptr.To(VolumeDefaultMode),
Sources: []corev1.VolumeProjection{
{
Secret: &corev1.SecretProjection{
Expand Down
Loading

0 comments on commit 6eb9d36

Please sign in to comment.