Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Mange <[email protected]>
  • Loading branch information
thibaultmg committed Jun 26, 2024
1 parent 2732d8f commit ad1fea5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import (
)

var (
log = ctrl.Log.WithName("controllers").WithName("ObservabilityAddon")
// r.InstallPrometheus, _ = strconv.ParseBool(os.Getenv(operatorconfig.InstallPrometheus))
log = ctrl.Log.WithName("controllers").WithName("ObservabilityAddon")
globalRes = []*unstructured.Unstructured{}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ func TestMain(m *testing.M) {

rootPath := filepath.Join("..", "..", "..")
spokeCrds := readCRDFiles(
filepath.Join(rootPath, "multiclusterobservability", "config", "crd", "bases", "observability.open-cluster-management.io_multiclusterobservabilities.yaml"),
filepath.Join(rootPath, "multiclusterobservability", "config", "crd", "bases", "observability.open-cluster-management.io_observabilityaddons.yaml"),
filepath.Join(rootPath, "endpointmetrics", "manifests", "prometheus", "crd", "servicemonitor_crd_0_53_1.yaml"),
filepath.Join(rootPath, "endpointmetrics", "manifests", "prometheus", "crd", "prometheusrule_crd_0_53_1.yaml"),
filepath.Join(rootPath, "endpointmetrics", "manifests", "prometheus", "crd", "prometheus_crd_0_73_2.yaml"),
)
testEnvSpoke = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("testdata", "crd"), filepath.Join("..", "..", "config", "crd", "bases")},
Expand All @@ -149,15 +145,15 @@ func TestMain(m *testing.M) {
panic(fmt.Sprintf("Failed to start spoke test environment: %v", err))
}

// spokeCrds = readCRDFiles(
// filepath.Join(rootPath, "multiclusterobservability", "config", "crd", "bases", "observability.open-cluster-management.io_multiclusterobservabilities.yaml"),
// filepath.Join(rootPath, "multiclusterobservability", "config", "crd", "bases", "observability.open-cluster-management.io_multiclusterobservabilities.yaml"),
// filepath.Join(rootPath, "endpointmetrics", "manifests", "prometheus", "crd", "servicemonitor_crd_0_53_1.yaml"),
// filepath.Join(rootPath, "endpointmetrics", "manifests", "prometheus", "crd", "prometheusrule_crd_0_53_1.yaml"),
// )
hubCRDs := readCRDFiles(
filepath.Join(rootPath, "multiclusterobservability", "config", "crd", "bases", "observability.open-cluster-management.io_multiclusterobservabilities.yaml"),
filepath.Join(rootPath, "endpointmetrics", "manifests", "prometheus", "crd", "servicemonitor_crd_0_53_1.yaml"),
)
hubCRDs = append(hubCRDs, spokeCrds...)

testEnvHub = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("testdata", "crd"), filepath.Join("..", "..", "..", "config", "crd", "bases")},
CRDs: spokeCrds,
CRDs: hubCRDs,
ControlPlaneStopTimeout: 5 * time.Minute,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ spec:
value: "false"
- name: PULL_SECRET
value: "REPLACE_WITH_IMAGEPULLSECRET"
- name: HOST_IP # Needed for microshift
valueFrom:
fieldRef:
fieldPath: status.hostIP
volumeMounts:
- name: hub-kubeconfig-secret
mountPath: "/spoke/hub-kubeconfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ rules:
- cronjobs
- jobs
verbs:
- '*'
- list
- watch
- apiGroups:
- certificates.k8s.io
resources:
Expand Down
31 changes: 0 additions & 31 deletions operators/pkg/deploying/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -57,8 +56,6 @@ func NewDeployer(client client.Client) *Deployer {
"ServiceAccount": deployer.updateServiceAccount,
"DaemonSet": deployer.updateDaemonSet,
"ServiceMonitor": deployer.updateServiceMonitor,
"Endpoints": deployer.updateEndpoints,
"CronJob": deployer.updateCronJob,
}
return deployer
}
Expand Down Expand Up @@ -366,34 +363,6 @@ func (d *Deployer) updateServiceMonitor(ctx context.Context, desiredObj, runtime
return nil
}

func (d *Deployer) updateEndpoints(ctx context.Context, desiredObj, runtimeObj *unstructured.Unstructured) error {
desiredEndpoints, runtimeEndpoints, err := unstructuredPairToTyped[corev1.Endpoints](desiredObj, runtimeObj)
if err != nil {
return err
}

if !apiequality.Semantic.DeepDerivative(desiredEndpoints.Subsets, runtimeEndpoints.Subsets) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredEndpoints)
}

return nil
}

func (d *Deployer) updateCronJob(ctx context.Context, desiredObj, runtimeObj *unstructured.Unstructured) error {
desiredCronJob, runtimeCronJob, err := unstructuredPairToTyped[batchv1.CronJob](desiredObj, runtimeObj)
if err != nil {
return err
}

if !apiequality.Semantic.DeepDerivative(desiredCronJob.Spec, runtimeCronJob.Spec) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredCronJob)
}

return nil
}

// unstructuredToType converts an unstructured.Unstructured object to a specified type.
// It marshals the object to JSON and then unmarshals it into the target type.
// The target parameter must be a pointer to the type T.
Expand Down

0 comments on commit ad1fea5

Please sign in to comment.