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

✨ allow specifying container proxy settings #1112

Merged
merged 2 commits into from
May 14, 2024
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
2 changes: 2 additions & 0 deletions api/v1alpha2/mondoooperatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type MondooOperatorConfigSpec struct {
SkipContainerResolution bool `json:"skipContainerResolution,omitempty"`
// HttpProxy specifies a proxy to use for HTTP requests to the Mondoo Platform.
HttpProxy *string `json:"httpProxy,omitempty"`
// ContainerProxy specifies a proxy to use for container images.
ContainerProxy *string `json:"containerProxy,omitempty"`
}

type Metrics struct {
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion cmd/mondoo-operator/garbage_collect/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/go-logr/logr"
"github.com/spf13/cobra"
"go.mondoo.com/cnspec/v10/policy/scan"
"go.mondoo.com/cnspec/v11/policy/scan"
"go.mondoo.com/mondoo-operator/pkg/client/scanapiclient"
"go.mondoo.com/mondoo-operator/pkg/utils/logger"
"k8s.io/utils/ptr"
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/k8s.mondoo.com_mondoooperatorconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ spec:
spec:
description: MondooOperatorConfigSpec defines the desired state of MondooOperatorConfig
properties:
containerProxy:
description: ContainerProxy specifies a proxy to use for container
images.
type: string
httpProxy:
description: HttpProxy specifies a proxy to use for HTTP requests
to the Mondoo Platform.
Expand Down
2 changes: 1 addition & 1 deletion controllers/container_image/deployment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (n *DeploymentHandler) syncConfigMap(ctx context.Context, clusterUid string
return false, err
}

desired, err := ConfigMap(integrationMrn, clusterUid, *n.Mondoo)
desired, err := ConfigMap(integrationMrn, clusterUid, *n.Mondoo, *n.MondooOperatorConfig)
if err != nil {
logger.Error(err, "failed to generate desired ConfigMap with inventory")
return false, err
Expand Down
14 changes: 10 additions & 4 deletions controllers/container_image/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// That's the mod k8s relies on https://github.com/kubernetes/kubernetes/blob/master/go.mod#L63

"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/mondoo-operator/api/v1alpha2"
"go.mondoo.com/mondoo-operator/pkg/constants"
"go.mondoo.com/mondoo-operator/pkg/feature_flags"
Expand Down Expand Up @@ -204,8 +204,8 @@ func CronJobName(prefix string) string {
return fmt.Sprintf("%s%s", prefix, CronJobNameSuffix)
}

func ConfigMap(integrationMRN, clusterUID string, m v1alpha2.MondooAuditConfig) (*corev1.ConfigMap, error) {
inv, err := Inventory(integrationMRN, clusterUID, m)
func ConfigMap(integrationMRN, clusterUID string, m v1alpha2.MondooAuditConfig, cfg v1alpha2.MondooOperatorConfig) (*corev1.ConfigMap, error) {
inv, err := Inventory(integrationMRN, clusterUID, m, cfg)
if err != nil {
return nil, err
}
Expand All @@ -223,7 +223,7 @@ func ConfigMapName(prefix string) string {
return fmt.Sprintf("%s%s", prefix, InventoryConfigMapBase)
}

func Inventory(integrationMRN, clusterUID string, m v1alpha2.MondooAuditConfig) (string, error) {
func Inventory(integrationMRN, clusterUID string, m v1alpha2.MondooAuditConfig, cfg v1alpha2.MondooOperatorConfig) (string, error) {
inv := &inventory.Inventory{
Metadata: &inventory.ObjectMeta{
Name: "mondoo-k8s-containers-inventory",
Expand Down Expand Up @@ -258,6 +258,12 @@ func Inventory(integrationMRN, clusterUID string, m v1alpha2.MondooAuditConfig)
}
}

if cfg.Spec.ContainerProxy != nil {
for i := range inv.Spec.Assets {
inv.Spec.Assets[i].Connections[0].Options["container-proxy"] = *cfg.Spec.ContainerProxy
}
}

invBytes, err := yaml.Marshal(inv)
if err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions controllers/mondoooperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (r *MondooOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl
return ctrl.Result{}, nil
}

if config.Spec.HttpProxy != nil {
urlParsed, err := url.Parse(*config.Spec.HttpProxy)
if config.Spec.ContainerProxy != nil {
preslavgerchev marked this conversation as resolved.
Show resolved Hide resolved
urlParsed, err := url.Parse(*config.Spec.ContainerProxy)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/nodes/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// That's the mod k8s relies on https://github.com/kubernetes/kubernetes/blob/master/go.mod#L63

"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/mondoo-operator/api/v1alpha2"
"go.mondoo.com/mondoo-operator/controllers/scanapi"
"go.mondoo.com/mondoo-operator/pkg/constants"
Expand Down
Loading
Loading