Skip to content

Commit

Permalink
feat: Adds the ability to inject ImagePullSecrets. Closes #946 (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
whynowy authored Nov 13, 2020
1 parent d9e7230 commit 4a500b0
Show file tree
Hide file tree
Showing 30 changed files with 1,121 additions and 664 deletions.
17 changes: 17 additions & 0 deletions api/event-bus.html

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

18 changes: 18 additions & 0 deletions api/event-bus.md

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

17 changes: 17 additions & 0 deletions api/event-source.html

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

18 changes: 18 additions & 0 deletions api/event-source.md

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

37 changes: 37 additions & 0 deletions api/openapi-spec/swagger.json

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

17 changes: 17 additions & 0 deletions api/sensor.html

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

18 changes: 18 additions & 0 deletions api/sensor.md

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

7 changes: 4 additions & 3 deletions controllers/eventbus/installer/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,10 @@ func (i *natsInstaller) buildStatefulSetSpec(serviceName, configmapName, authSec
Labels: podTemplateLabels,
},
Spec: corev1.PodSpec{
NodeSelector: i.eventBus.Spec.NATS.Native.NodeSelector,
Tolerations: i.eventBus.Spec.NATS.Native.Tolerations,
SecurityContext: i.eventBus.Spec.NATS.Native.SecurityContext,
NodeSelector: i.eventBus.Spec.NATS.Native.NodeSelector,
Tolerations: i.eventBus.Spec.NATS.Native.Tolerations,
SecurityContext: i.eventBus.Spec.NATS.Native.SecurityContext,
ImagePullSecrets: i.eventBus.Spec.NATS.Native.ImagePullSecrets,
Volumes: []corev1.Volume{
{
Name: "config-volume",
Expand Down
20 changes: 20 additions & 0 deletions controllers/eventbus/installer/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ var (
NATS: &v1alpha1.NATSBus{
Native: &v1alpha1.NativeStrategy{
Auth: &v1alpha1.AuthStrategyToken,
ImagePullSecrets: []corev1.LocalObjectReference{
{
Name: "test",
},
},
},
},
},
Expand Down Expand Up @@ -216,4 +221,19 @@ func TestBuildPersistStatefulSetSpec(t *testing.T) {
assert.NoError(t, err)
assert.True(t, len(ss.Spec.VolumeClaimTemplates) > 0)
})

t.Run("installation with image pull secrets", func(t *testing.T) {
cl := fake.NewFakeClient(testEventBus)
installer := &natsInstaller{
client: cl,
eventBus: testEventBus,
streamingImage: testStreamingImage,
metricsImage: testMetricsImage,
labels: testLabels,
logger: logging.NewArgoEventsLogger(),
}
ss, err := installer.buildStatefulSet("svcName", "cmName", "secretName")
assert.NoError(t, err)
assert.True(t, len(ss.Spec.Template.Spec.ImagePullSecrets) > 0)
})
}
1 change: 1 addition & 0 deletions controllers/eventsource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func buildDeploymentSpec(args *AdaptorArgs) (*appv1.DeploymentSpec, error) {
spec.Template.Spec.NodeSelector = args.EventSource.Spec.Template.NodeSelector
spec.Template.Spec.Tolerations = args.EventSource.Spec.Template.Tolerations
spec.Template.Spec.Affinity = args.EventSource.Spec.Template.Affinity
spec.Template.Spec.ImagePullSecrets = args.EventSource.Spec.Template.ImagePullSecrets
}
allEventTypes := eventsources.GetEventingServers(args.EventSource)
recreateTypes := make(map[apicommon.EventSourceType]bool)
Expand Down
9 changes: 9 additions & 0 deletions controllers/eventsource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/argoproj/argo-events/common/logging"
"github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
)

const (
Expand All @@ -25,6 +26,13 @@ var (
func Test_BuildDeployment(t *testing.T) {
testEventSource := fakeEmptyEventSource()
testEventSource.Spec.HDFS = fakeHDFSEventSourceMap("test")
testEventSource.Spec.Template = &v1alpha1.Template{
ImagePullSecrets: []corev1.LocalObjectReference{
{
Name: "test",
},
},
}
t.Run("test build HDFS", func(t *testing.T) {
args := &AdaptorArgs{
Image: testImage,
Expand All @@ -50,6 +58,7 @@ func Test_BuildDeployment(t *testing.T) {
}
}
assert.True(t, hasAuthVolume)
assert.True(t, len(deployment.Spec.Template.Spec.ImagePullSecrets) > 0)
assert.True(t, cmRefs > 0)
assert.True(t, secretRefs > 0)
})
Expand Down
1 change: 1 addition & 0 deletions controllers/sensor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func buildDeploymentSpec(args *AdaptorArgs) (*appv1.DeploymentSpec, error) {
spec.Template.Spec.SecurityContext = args.Sensor.Spec.Template.SecurityContext
spec.Template.Spec.NodeSelector = args.Sensor.Spec.Template.NodeSelector
spec.Template.Spec.Tolerations = args.Sensor.Spec.Template.Tolerations
spec.Template.Spec.ImagePullSecrets = args.Sensor.Spec.Template.ImagePullSecrets
}
return spec, nil
}
Expand Down
40 changes: 7 additions & 33 deletions controllers/sensor/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ var (
Spec: v1alpha1.SensorSpec{
Template: &v1alpha1.Template{
ServiceAccountName: "fake-sa",
ImagePullSecrets: []corev1.LocalObjectReference{
{
Name: "test",
},
},
Container: &corev1.Container{
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -90,38 +95,6 @@ var (
},
}

sensorObjNoTemplate = &v1alpha1.Sensor{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-sensor",
Namespace: testNamespace,
},
Spec: v1alpha1.SensorSpec{
Triggers: []v1alpha1.Trigger{
{
Template: &v1alpha1.TriggerTemplate{
Name: "fake-trigger",
K8s: &v1alpha1.StandardK8STrigger{
GroupVersionResource: metav1.GroupVersionResource{
Group: "k8s.io",
Version: "",
Resource: "pods",
},
Operation: "create",
Source: &v1alpha1.ArtifactLocation{},
},
},
},
},
Dependencies: []v1alpha1.EventDependency{
{
Name: "fake-dep",
EventSourceName: "fake-source",
EventName: "fake-one",
},
},
},
}

fakeEventBus = &eventbusv1alpha1.EventBus{
TypeMeta: metav1.TypeMeta{
APIVersion: eventbusv1alpha1.SchemeGroupVersion.String(),
Expand Down Expand Up @@ -156,7 +129,7 @@ var (
)

func Test_BuildDeployment(t *testing.T) {
sensorObjs := []*v1alpha1.Sensor{sensorObj, sensorObjNoTemplate}
sensorObjs := []*v1alpha1.Sensor{sensorObj, sensorObj}
t.Run("test build with eventbus", func(t *testing.T) {
for _, sObj := range sensorObjs {
args := &AdaptorArgs{
Expand All @@ -177,6 +150,7 @@ func Test_BuildDeployment(t *testing.T) {
}
}
assert.True(t, hasAuthVolume)
assert.True(t, len(deployment.Spec.Template.Spec.ImagePullSecrets) > 0)
}
})
}
Expand Down
Loading

0 comments on commit 4a500b0

Please sign in to comment.