-
Notifications
You must be signed in to change notification settings - Fork 33
/
image_stream.go
47 lines (36 loc) · 1.65 KB
/
image_stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package falcon
import (
"context"
"fmt"
"reflect"
falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
"github.com/crowdstrike/falcon-operator/internal/controller/assets"
"github.com/crowdstrike/falcon-operator/pkg/common"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/errors"
types "k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
imagev1 "github.com/openshift/api/image/v1"
)
const (
imageStreamName = "falcon-sidecar-container"
)
func (r *FalconContainerReconciler) reconcileImageStream(ctx context.Context, log logr.Logger, falconContainer *falconv1alpha1.FalconContainer) (*imagev1.ImageStream, error) {
imageStream := assets.ImageStream(imageStreamName, r.imageNamespace(falconContainer), common.FalconSidecarSensor)
existingImageStream := &imagev1.ImageStream{}
err := r.Client.Get(ctx, types.NamespacedName{Name: imageStreamName, Namespace: r.imageNamespace(falconContainer)}, existingImageStream)
if err != nil {
if errors.IsNotFound(err) {
if err = ctrl.SetControllerReference(falconContainer, imageStream, r.Scheme); err != nil {
return &imagev1.ImageStream{}, fmt.Errorf("unable to set controller reference on image stream %s: %v", imageStreamName, err)
}
return imageStream, r.Create(ctx, log, falconContainer, imageStream)
}
return &imagev1.ImageStream{}, fmt.Errorf("unable to query existing image stream %s: %v", imageStreamName, err)
}
if reflect.DeepEqual(imageStream.Spec, existingImageStream.Spec) {
return existingImageStream, nil
}
existingImageStream.Spec = imageStream.Spec
return existingImageStream, r.Update(ctx, log, falconContainer, existingImageStream)
}