Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update all the things #241

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions api/v1/porterconfig_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestPorterConfigSpec_MergeConfig(t *testing.T) {
t.Run("empty is ignored", func(t *testing.T) {
nsConfig := PorterConfigSpec{
Verbosity: pointer.String("info"),
Verbosity: ptr.To("info"),
}

instConfig := PorterConfigSpec{}

config, err := nsConfig.MergeConfig(instConfig)
require.NoError(t, err)
assert.Equal(t, pointer.String("info"), config.Verbosity)
assert.Equal(t, ptr.To("info"), config.Verbosity)
})

t.Run("override", func(t *testing.T) {
nsConfig := PorterConfigSpec{
Verbosity: pointer.String("info"),
Verbosity: ptr.To("info"),
}

instConfig := PorterConfigSpec{
Verbosity: pointer.String("debug"),
Verbosity: ptr.To("debug"),
Telemetry: TelemetryConfig{
Enabled: pointer.Bool(true),
Enabled: ptr.To(true),
},
}

config, err := nsConfig.MergeConfig(instConfig)
require.NoError(t, err)
assert.Equal(t, pointer.String("debug"), config.Verbosity)
assert.Equal(t, pointer.Bool(true), config.Telemetry.Enabled)
assert.Equal(t, ptr.To("debug"), config.Verbosity)
assert.Equal(t, ptr.To(true), config.Telemetry.Enabled)
})
}

Expand All @@ -51,14 +51,14 @@ func TestPorterConfigSpec_ToPorterDocument(t *testing.T) {
{
name: "All fields set",
cfg: PorterConfigSpec{
Verbosity: pointer.String("debug"),
Namespace: pointer.String("test"),
Verbosity: ptr.To("debug"),
Namespace: ptr.To("test"),
Experimental: []string{"build-drivers"},
BuildDriver: pointer.String("buildkit"),
DefaultStorage: pointer.String("in-cluster-mongodb"),
DefaultSecrets: pointer.String("keyvault"),
DefaultStoragePlugin: pointer.String("mongodb"),
DefaultSecretsPlugin: pointer.String("kubernetes.secrets"),
BuildDriver: ptr.To("buildkit"),
DefaultStorage: ptr.To("in-cluster-mongodb"),
DefaultSecrets: ptr.To("keyvault"),
DefaultStoragePlugin: ptr.To("mongodb"),
DefaultSecretsPlugin: ptr.To("kubernetes.secrets"),
Storage: []StorageConfig{
{PluginConfig{
Name: "in-cluster-mongodb",
Expand Down Expand Up @@ -98,8 +98,8 @@ secrets:
{
name: "Storage config not provided",
cfg: PorterConfigSpec{
DefaultSecretsPlugin: pointer.String("kubernetes.secrets"),
DefaultStorage: pointer.String("in-cluster-mongodb"),
DefaultSecretsPlugin: ptr.To("kubernetes.secrets"),
DefaultStorage: ptr.To("in-cluster-mongodb"),
Storage: []StorageConfig{
{PluginConfig{
Name: "in-cluster-mongodb",
Expand All @@ -117,8 +117,8 @@ storage:
{
name: "Secrets config not provided",
cfg: PorterConfigSpec{
DefaultStorage: pointer.String("in-cluster-mongodb"),
DefaultSecrets: pointer.String("kubernetes-secrets"),
DefaultStorage: ptr.To("in-cluster-mongodb"),
DefaultSecrets: ptr.To("kubernetes-secrets"),
Storage: []StorageConfig{
{PluginConfig{
Name: "in-cluster-mongodb",
Expand Down Expand Up @@ -148,8 +148,8 @@ secrets:
{
name: "All Telemetry config provided",
cfg: PorterConfigSpec{
DefaultStorage: pointer.String("in-cluster-mongodb"),
DefaultSecrets: pointer.String("kubernetes-secrets"),
DefaultStorage: ptr.To("in-cluster-mongodb"),
DefaultSecrets: ptr.To("kubernetes-secrets"),
Storage: []StorageConfig{
{PluginConfig{
Name: "in-cluster-mongodb",
Expand All @@ -164,14 +164,14 @@ secrets:
}},
},
Telemetry: TelemetryConfig{
Enabled: pointer.Bool(true),
Protocol: pointer.String("grpc"),
Endpoint: pointer.String("127.0.0.1:4317"),
Insecure: pointer.Bool(true),
Compression: pointer.String("gzip"),
Timeout: pointer.String("3s"),
StartTimeout: pointer.String("100ms"),
RedirectToFile: pointer.String("foo"),
Enabled: ptr.To(true),
Protocol: ptr.To("grpc"),
Endpoint: ptr.To("127.0.0.1:4317"),
Insecure: ptr.To(true),
Compression: ptr.To("gzip"),
Timeout: ptr.To("3s"),
StartTimeout: ptr.To("100ms"),
RedirectToFile: ptr.To("foo"),
},
},
expDocument: []byte(`default-storage: in-cluster-mongodb
Expand Down
30 changes: 15 additions & 15 deletions controllers/agentaction_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -304,7 +304,7 @@ func (r *AgentActionReconciler) createConfigSecret(ctx context.Context, log logr
Labels: labels,
},
Type: corev1.SecretTypeOpaque,
Immutable: pointer.Bool(true),
Immutable: ptr.To(true),
Data: map[string][]byte{
"config.yaml": porterCfgB,
},
Expand Down Expand Up @@ -340,7 +340,7 @@ func (r *AgentActionReconciler) createWorkdirSecret(ctx context.Context, log log
Labels: labels,
},
Type: corev1.SecretTypeOpaque,
Immutable: pointer.Bool(true),
Immutable: ptr.To(true),
Data: action.Spec.Files,
}

Expand Down Expand Up @@ -414,13 +414,13 @@ func (r *AgentActionReconciler) createAgentJob(ctx context.Context, log logr.Log
Kind: action.Kind,
Name: action.Name,
UID: action.UID,
Controller: pointer.Bool(true),
BlockOwnerDeletion: pointer.Bool(true),
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
},
},
},
Spec: batchv1.JobSpec{
Completions: pointer.Int32(1),
Completions: ptr.To(int32(1)),
BackoffLimit: agentCfg.GetRetryLimit(),
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -451,11 +451,11 @@ func (r *AgentActionReconciler) createAgentJob(ctx context.Context, log logr.Log
ImagePullSecrets: nil, // TODO: Make pulling from a private registry possible
SecurityContext: &corev1.PodSecurityContext{
// Run as the well-known nonroot user that Porter uses for the invocation image and the agent
RunAsUser: pointer.Int64(65532),
RunAsUser: ptr.To(int64(65532)),
// Porter builds the bundles with the root group having the same permissions as the owner
// So make sure that we are running as the root group
RunAsGroup: pointer.Int64(0),
FSGroup: pointer.Int64(0),
RunAsGroup: ptr.To(int64(0)),
FSGroup: ptr.To(int64(0)),
},
},
},
Expand Down Expand Up @@ -562,8 +562,8 @@ func (r *AgentActionReconciler) resolvePorterConfig(ctx context.Context, log log

// Provide a safe default config in case nothing is defined anywhere
defaultCfg := porterv1.PorterConfigSpec{
DefaultStorage: pointer.String("in-cluster-mongodb"),
DefaultSecretsPlugin: pointer.String("kubernetes.secrets"),
DefaultStorage: ptr.To("in-cluster-mongodb"),
DefaultSecretsPlugin: ptr.To("kubernetes.secrets"),
Storage: []porterv1.StorageConfig{
{PluginConfig: porterv1.PluginConfig{
Name: "in-cluster-mongodb",
Expand Down Expand Up @@ -652,7 +652,7 @@ func (r *AgentActionReconciler) getAgentEnv(action *porterv1.AgentAction, agentC
LocalObjectReference: corev1.LocalObjectReference{
Name: "porter-env",
},
Optional: pointer.Bool(true),
Optional: ptr.To(true),
},
},
}
Expand All @@ -677,7 +677,7 @@ func (r *AgentActionReconciler) getAgentVolumes(ctx context.Context, log logr.Lo
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: configSecret.Name,
Optional: pointer.Bool(false),
Optional: ptr.To(false),
},
},
},
Expand All @@ -686,7 +686,7 @@ func (r *AgentActionReconciler) getAgentVolumes(ctx context.Context, log logr.Lo
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: workdirSecret.Name,
Optional: pointer.Bool(false),
Optional: ptr.To(false),
},
},
},
Expand All @@ -713,7 +713,7 @@ func (r *AgentActionReconciler) getAgentVolumes(ctx context.Context, log logr.Lo
Secret: &corev1.SecretVolumeSource{
Items: []corev1.KeyToPath{{Key: ".dockerconfigjson", Path: ".docker/config.json"}},
SecretName: imgPullSecret.Name,
Optional: pointer.Bool(false),
Optional: ptr.To(false),
},
},
})
Expand Down
36 changes: 18 additions & 18 deletions controllers/agentaction_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -520,7 +520,7 @@ func TestAgentActionReconciler_createConfigSecret(t *testing.T) {
Labels: sharedLabels,
},
Type: corev1.SecretTypeBasicAuth,
Immutable: pointer.Bool(false),
Immutable: ptr.To(false),
Data: map[string][]byte{
"config.yaml": porterCfgB,
},
Expand All @@ -536,12 +536,12 @@ func TestAgentActionReconciler_createConfigSecret(t *testing.T) {
if test.created {
assert.Equal(t, "porter-hello-", secret.GenerateName, "incorrect secret name")
assert.Equal(t, corev1.SecretTypeOpaque, secret.Type, "expected the secret to be of type Opaque")
assert.Equal(t, pointer.Bool(true), secret.Immutable, "expected the secret to be immutable")
assert.Equal(t, ptr.To(true), secret.Immutable, "expected the secret to be immutable")
assert.Contains(t, secret.Data, "config.yaml", "expected the secret to have config.yaml")
} else {
assert.Equal(t, "existing-", secret.GenerateName, "incorrect secret name")
assert.Equal(t, corev1.SecretTypeBasicAuth, secret.Type, "expected the secret to be of type Opaque")
assert.Equal(t, pointer.Bool(false), secret.Immutable, "expected the secret to be immutable")
assert.Equal(t, ptr.To(false), secret.Immutable, "expected the secret to be immutable")
assert.Contains(t, secret.Data, "config.yaml", "expected the secret to have config.yaml")

}
Expand Down Expand Up @@ -652,7 +652,7 @@ func TestAgentActionReconciler_createWorkdirSecret(t *testing.T) {
Labels: sharedLabels,
},
Type: corev1.SecretTypeBasicAuth,
Immutable: pointer.Bool(false),
Immutable: ptr.To(false),
Data: map[string][]byte{
"existing.yaml": []byte(`{}`),
},
Expand All @@ -667,12 +667,12 @@ func TestAgentActionReconciler_createWorkdirSecret(t *testing.T) {
if test.created {
assert.Equal(t, "porter-hello-", secret.GenerateName, "incorrect secret name")
assert.Equal(t, corev1.SecretTypeOpaque, secret.Type, "expected the secret to be of type Opaque")
assert.Equal(t, pointer.Bool(true), secret.Immutable, "expected the secret to be immutable")
assert.Equal(t, ptr.To(true), secret.Immutable, "expected the secret to be immutable")
assert.Contains(t, secret.Data, "installation.yaml", "expected the secret to have config.yaml")
} else {
assert.Equal(t, "existing-", secret.GenerateName, "incorrect secret name")
assert.Equal(t, corev1.SecretTypeBasicAuth, secret.Type, "expected the secret to be of type Opaque")
assert.Equal(t, pointer.Bool(false), secret.Immutable, "expected the secret to be immutable")
assert.Equal(t, ptr.To(false), secret.Immutable, "expected the secret to be immutable")
assert.Contains(t, secret.Data, "existing.yaml", "expected the secret to have config.yaml")
}
assert.Equal(t, action.Namespace, secret.Namespace, "incorrect secret namespace")
Expand Down Expand Up @@ -705,14 +705,14 @@ func TestAgentActionReconciler_createAgentJob(t *testing.T) {
Kind: "AgentAction",
Name: "porter-hello",
UID: "random-uid",
Controller: pointer.Bool(true),
BlockOwnerDeletion: pointer.Bool(true),
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
}
assert.Equal(t, wantOwnerRef, job.OwnerReferences[0], "incorrect owner reference")
assertSharedAgentLabels(t, job.Labels)
assertContains(t, job.Labels, porterv1.LabelJobType, porterv1.JobTypeAgent, "incorrect label")
assertContains(t, job.Labels, "testLabel", "abc123", "incorrect label")
assert.Equal(t, pointer.Int32(1), job.Spec.Completions, "incorrect job completions")
assert.Equal(t, ptr.To(int32(1)), job.Spec.Completions, "incorrect job completions")
assert.Nil(t, job.Spec.BackoffLimit, "incorrect job back off limit")

// Verify the job pod template
Expand All @@ -726,9 +726,9 @@ func TestAgentActionReconciler_createAgentJob(t *testing.T) {
assert.Equal(t, porterv1.VolumePorterConfigName, podTemplate.Spec.Volumes[1].Name, "expected the porter-config volume")
assert.Equal(t, porterv1.VolumePorterWorkDirName, podTemplate.Spec.Volumes[2].Name, "expected the porter-workdir volume")
assert.Equal(t, "porteraccount", podTemplate.Spec.ServiceAccountName, "incorrect service account for the pod")
assert.Equal(t, pointer.Int64(65532), podTemplate.Spec.SecurityContext.RunAsUser, "incorrect RunAsUser")
assert.Equal(t, pointer.Int64(0), podTemplate.Spec.SecurityContext.RunAsGroup, "incorrect RunAsGroup")
assert.Equal(t, pointer.Int64(0), podTemplate.Spec.SecurityContext.FSGroup, "incorrect FSGroup")
assert.Equal(t, ptr.To(int64(65532)), podTemplate.Spec.SecurityContext.RunAsUser, "incorrect RunAsUser")
assert.Equal(t, ptr.To(int64(0)), podTemplate.Spec.SecurityContext.RunAsGroup, "incorrect RunAsGroup")
assert.Equal(t, ptr.To(int64(0)), podTemplate.Spec.SecurityContext.FSGroup, "incorrect FSGroup")

// Verify the agent container
agentContainer := podTemplate.Spec.Containers[0]
Expand All @@ -745,7 +745,7 @@ func TestAgentActionReconciler_createAgentJob(t *testing.T) {
assertEnvVar(t, agentContainer.Env, "SERVICE_ACCOUNT", "installeraccount")
assertEnvVar(t, agentContainer.Env, "LABELS", "getporter.org/jobType=bundle-installer getporter.org/managed=true getporter.org/resourceGeneration=1 getporter.org/resourceKind=AgentAction getporter.org/resourceName=porter-hello getporter.org/retry= testLabel=abc123")
assertEnvVar(t, agentContainer.Env, "AFFINITY_MATCH_LABELS", "getporter.org/resourceKind=AgentAction getporter.org/resourceName=porter-hello getporter.org/resourceGeneration=1 getporter.org/retry=")
assertEnvFrom(t, agentContainer.EnvFrom, "porter-env", pointer.Bool(true))
assertEnvFrom(t, agentContainer.EnvFrom, "porter-env", ptr.To(true))
assert.Len(t, agentContainer.VolumeMounts, 4)
assertVolumeMount(t, agentContainer.VolumeMounts, porterv1.VolumePorterConfigName, porterv1.VolumePorterConfigPath)
assertVolumeMount(t, agentContainer.VolumeMounts, porterv1.VolumePorterSharedName, porterv1.VolumePorterSharedPath)
Expand Down Expand Up @@ -834,9 +834,9 @@ func TestAgentActionReconciler_createAgentJob_withImagePullSecrets(t *testing.T)
assert.Equal(t, testSA.ImagePullSecrets[0].Name, podTemplate.Spec.Volumes[3].Secret.SecretName, "expected the service account image pull secret name")
assert.Equal(t, porterv1.VolumePorterPluginsName, podTemplate.Spec.Volumes[4].Name, "expected the porter-workdir volume")
assert.Equal(t, "porteraccount", podTemplate.Spec.ServiceAccountName, "incorrect service account for the pod")
assert.Equal(t, pointer.Int64(65532), podTemplate.Spec.SecurityContext.RunAsUser, "incorrect RunAsUser")
assert.Equal(t, pointer.Int64(0), podTemplate.Spec.SecurityContext.RunAsGroup, "incorrect RunAsGroup")
assert.Equal(t, pointer.Int64(0), podTemplate.Spec.SecurityContext.FSGroup, "incorrect FSGroup")
assert.Equal(t, ptr.To(int64(65532)), podTemplate.Spec.SecurityContext.RunAsUser, "incorrect RunAsUser")
assert.Equal(t, ptr.To(int64(0)), podTemplate.Spec.SecurityContext.RunAsGroup, "incorrect RunAsGroup")
assert.Equal(t, ptr.To(int64(0)), podTemplate.Spec.SecurityContext.FSGroup, "incorrect FSGroup")

// Verify the agent container
agentContainer := podTemplate.Spec.Containers[0]
Expand All @@ -853,7 +853,7 @@ func TestAgentActionReconciler_createAgentJob_withImagePullSecrets(t *testing.T)
assertEnvVar(t, agentContainer.Env, "SERVICE_ACCOUNT", "installeraccount")
assertEnvVar(t, agentContainer.Env, "LABELS", "getporter.org/jobType=bundle-installer getporter.org/managed=true getporter.org/resourceGeneration=1 getporter.org/resourceKind=AgentAction getporter.org/resourceName=porter-hello getporter.org/retry= testLabel=abc123")
assertEnvVar(t, agentContainer.Env, "AFFINITY_MATCH_LABELS", "getporter.org/resourceKind=AgentAction getporter.org/resourceName=porter-hello getporter.org/resourceGeneration=1 getporter.org/retry=")
assertEnvFrom(t, agentContainer.EnvFrom, "porter-env", pointer.Bool(true))
assertEnvFrom(t, agentContainer.EnvFrom, "porter-env", ptr.To(true))
assert.Len(t, agentContainer.VolumeMounts, 5)
assertVolumeMount(t, agentContainer.VolumeMounts, porterv1.VolumePorterConfigName, porterv1.VolumePorterConfigPath)
assertVolumeMount(t, agentContainer.VolumeMounts, porterv1.VolumePorterSharedName, porterv1.VolumePorterSharedPath)
Expand Down
14 changes: 7 additions & 7 deletions controllers/agentconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand Down Expand Up @@ -214,8 +214,8 @@ func (r *AgentConfigReconciler) createEmptyPluginVolume(ctx context.Context, log
Kind: agentCfg.Kind,
Name: agentCfg.Name,
UID: agentCfg.UID,
Controller: pointer.Bool(true),
BlockOwnerDeletion: pointer.Bool(true),
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
},
},
},
Expand Down Expand Up @@ -282,8 +282,8 @@ func (r *AgentConfigReconciler) createAgentAction(ctx context.Context, log logr.
Kind: agentCfg.Kind,
Name: agentCfg.Name,
UID: agentCfg.UID,
Controller: pointer.Bool(true),
BlockOwnerDeletion: pointer.Bool(true),
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
},
},
},
Expand Down Expand Up @@ -396,8 +396,8 @@ func (r *AgentConfigReconciler) createHashPVC(ctx context.Context, log logr.Logg
Kind: agentCfg.Kind,
Name: agentCfg.Name,
UID: agentCfg.UID,
Controller: pointer.Bool(true),
BlockOwnerDeletion: pointer.Bool(true),
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
},
},
},
Expand Down
Loading