Skip to content

Commit

Permalink
Merge branch 'stolostron:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
coleenquadros authored Apr 2, 2024
2 parents e57c18f + 75d9568 commit 49d7c0b
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 126 deletions.
2 changes: 1 addition & 1 deletion COMPONENT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.10.0
2.11.0
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestEvluateMatchExpression(t *testing.T) {
expr: metav1.LabelSelectorRequirement{
Key: "test_key",
Operator: "In",
Values: []string{"SNO"},
Values: []string{snoClusterType},
},
expectedResult: false,
},
Expand All @@ -31,7 +31,7 @@ func TestEvluateMatchExpression(t *testing.T) {
expr: metav1.LabelSelectorRequirement{
Key: "clusterType",
Operator: "test_op",
Values: []string{"SNO"},
Values: []string{snoClusterType},
},
expectedResult: false,
},
Expand All @@ -40,17 +40,17 @@ func TestEvluateMatchExpression(t *testing.T) {
expr: metav1.LabelSelectorRequirement{
Key: "clusterType",
Operator: "NotIn",
Values: []string{"SNO"},
Values: []string{snoClusterType},
},
clusterType: "SNO",
clusterType: snoClusterType,
expectedResult: false,
},
{
name: "filter SNO rule in non-SNO",
expr: metav1.LabelSelectorRequirement{
Key: "clusterType",
Operator: "In",
Values: []string{"SNO"},
Values: []string{snoClusterType},
},
clusterType: "",
expectedResult: false,
Expand All @@ -60,7 +60,7 @@ func TestEvluateMatchExpression(t *testing.T) {
expr: metav1.LabelSelectorRequirement{
Key: "clusterType",
Operator: "NotIn",
Values: []string{"SNO"},
Values: []string{snoClusterType},
},
clusterType: "",
expectedResult: true,
Expand All @@ -70,9 +70,9 @@ func TestEvluateMatchExpression(t *testing.T) {
expr: metav1.LabelSelectorRequirement{
Key: "clusterType",
Operator: "In",
Values: []string{"SNO"},
Values: []string{snoClusterType},
},
clusterType: "SNO",
clusterType: snoClusterType,
expectedResult: true,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func getCommands(params CollectorParams) []string {
if !installPrometheus {
commands = append(commands, "--from-ca-file="+caFile)
}
if params.clusterType != "" {
if params.clusterType != defaultClusterType {
commands = append(commands, fmt.Sprintf("--label=\"clusterType=%s\"", params.clusterType))
}

Expand Down Expand Up @@ -203,32 +203,39 @@ func createDeployment(params CollectorParams) *appsv1.Deployment {
},
},
},
{
Name: "secret-kube-rbac-proxy-tls",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: secretName + "-kube-rbac-tls",
}

if params.clusterType != ocpThreeClusterType {
serviceCAOperatorGenerated := []corev1.Volume{
{
Name: "secret-kube-rbac-proxy-tls",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: secretName + "-kube-rbac-tls",
},
},
},
},
{
Name: "secret-kube-rbac-proxy-metric",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: secretName + "-kube-rbac-proxy-metric",
{
Name: "secret-kube-rbac-proxy-metric",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: secretName + "-kube-rbac-proxy-metric",
},
},
},
},
{
Name: "metrics-client-ca",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: secretName + "-clientca-metric",
{
Name: "metrics-client-ca",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: secretName + "-clientca-metric",
},
},
},
},
},
}

volumes = append(volumes, serviceCAOperatorGenerated...)
}
mounts := []corev1.VolumeMount{
{
Expand Down Expand Up @@ -362,15 +369,12 @@ func createDeployment(params CollectorParams) *appsv1.Deployment {
}

if hubMetricsCollector {
//to avoid hub metrics collector from sending status
// to avoid hub metrics collector from sending status
metricsCollectorDep.Spec.Template.Spec.Containers[0].Env = append(metricsCollectorDep.Spec.Template.Spec.Containers[0].Env,
corev1.EnvVar{
Name: "STANDALONE",
Value: "true",
})

//Since there is no obsAddOn for hub-metrics-collector, we need to set the resources here
metricsCollectorDep.Spec.Template.Spec.Containers[0].Resources = operatorconfig.HubMetricsCollectorResources
}

privileged := false
Expand Down Expand Up @@ -760,7 +764,7 @@ func getMetricsAllowlist(ctx context.Context, c client.Client,
} else {
if cm.Data != nil {
configmapKey := operatorconfig.MetricsConfigMapKey
if clusterType == "ocp3" {
if clusterType == ocpThreeClusterType {
configmapKey = operatorconfig.MetricsOcp311ConfigMapKey
}
err = yaml.Unmarshal([]byte(cm.Data[configmapKey]), l)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestMetricsCollector(t *testing.T) {
params := CollectorParams{
isUWL: false,
clusterID: testClusterID,
clusterType: "",
clusterType: defaultClusterType,
obsAddonSpec: obsAddon,
hubInfo: *hubInfo,
allowlist: list,
Expand All @@ -212,7 +212,7 @@ func TestMetricsCollector(t *testing.T) {

params.replicaCount = 1
params.clusterID = testClusterID + "-update"
params.clusterType = "SNO"
params.clusterType = snoClusterType
_, err = updateMetricsCollector(ctx, c, params, false)
if err != nil {
t.Fatalf("Failed to create metrics collector deployment: (%v)", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/stolostron/multicluster-observability-operator/operators/endpointmetrics/pkg/rendering"
"github.com/stolostron/multicluster-observability-operator/operators/endpointmetrics/pkg/util"
oav1beta1 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1"
oav1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1"
operatorconfig "github.com/stolostron/multicluster-observability-operator/operators/pkg/config"
"github.com/stolostron/multicluster-observability-operator/operators/pkg/deploying"
rendererutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/rendering"
Expand All @@ -47,14 +48,18 @@ var (

const (
obAddonName = "observability-addon"
mcoCRName = "observability"
ownerLabelKey = "owner"
ownerLabelValue = "observabilityaddon"
obsAddonFinalizer = "observability.open-cluster-management.io/addon-cleanup"
promSvcName = "prometheus-k8s"
promNamespace = "openshift-monitoring"
openShiftClusterMonitoringlabel = "openshift.io/cluster-monitoring"
hubMetricsCollectionNamespace = "open-cluster-management-observability"
)

const (
defaultClusterType = ""
ocpThreeClusterType = "ocp3"
snoClusterType = "SNO"
)

var (
Expand Down Expand Up @@ -157,13 +162,15 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R
}
hubInfo.ClusterName = string(hubSecret.Data[operatorconfig.ClusterNameKey])

clusterType := ""
clusterType := defaultClusterType
clusterID := ""

//read the image configmap
// read the image configmap
imagesCM := &corev1.ConfigMap{}
err = r.Client.Get(ctx, types.NamespacedName{Name: operatorconfig.ImageConfigMap,
Namespace: namespace}, imagesCM)
err = r.Client.Get(ctx, types.NamespacedName{
Name: operatorconfig.ImageConfigMap,
Namespace: namespace,
}, imagesCM)
if err != nil {
log.Error(err, "Failed to get images configmap")
return ctrl.Result{}, err
Expand All @@ -180,8 +187,10 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R
if !installPrometheus {
// If no prometheus service found, set status as NotSupported
promSvc := &corev1.Service{}
err = r.Client.Get(ctx, types.NamespacedName{Name: promSvcName,
Namespace: promNamespace}, promSvc)
err = r.Client.Get(ctx, types.NamespacedName{
Name: promSvcName,
Namespace: promNamespace,
}, promSvc)
if err != nil {
if errors.IsNotFound(err) {
log.Error(err, "OCP prometheus service does not exist")
Expand All @@ -199,11 +208,11 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R
// OCP 3.11 has no cluster id, set it as empty string
clusterID = ""
// to differentiate ocp 3.x
clusterType = "ocp3"
clusterType = ocpThreeClusterType
}
isSNO, err := isSNO(ctx, r.Client)
if err == nil && isSNO {
clusterType = "SNO"
clusterType = snoClusterType
}
err = createMonitoringClusterRoleBinding(ctx, r.Client)
if err != nil {
Expand All @@ -214,7 +223,7 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R
return ctrl.Result{}, err
}
} else {
//Render the prometheus templates
// Render the prometheus templates
renderer := rendererutil.NewRenderer()
toDeploy, err := rendering.Render(renderer, r.Client, hubInfo)
if err != nil {
Expand All @@ -240,11 +249,22 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R
return ctrl.Result{}, err
}

forceRestart := false
if req.Name == mtlsCertName || req.Name == mtlsCaName || req.Name == caConfigmapName {
forceRestart = true
}
forceRestart := req.Name == mtlsCertName || req.Name == mtlsCaName || req.Name == caConfigmapName

if obsAddon.Spec.EnableMetrics || hubMetricsCollector {
if hubMetricsCollector {
mcoList := &oav1beta2.MultiClusterObservabilityList{}
err := r.HubClient.List(ctx, mcoList, client.InNamespace(corev1.NamespaceAll))
if err != nil {
log.Error(err, "Failed to get multiclusterobservability")
return ctrl.Result{}, err
}
if len(mcoList.Items) != 1 {
log.Error(nil, fmt.Sprintf("Expected 1 multiclusterobservability, found %d", len(mcoList.Items)))
return ctrl.Result{}, nil
}
obsAddon.Spec = *mcoList.Items[0].Spec.ObservabilityAddonSpec
}
created, err := updateMetricsCollectors(
ctx,
r.Client,
Expand All @@ -253,7 +273,6 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R
clusterType,
1,
forceRestart)

if err != nil {
util.ReportStatus(ctx, r.Client, obsAddon, "Degraded", !hubMetricsCollector)
return ctrl.Result{}, err
Expand All @@ -271,13 +290,14 @@ func (r *ObservabilityAddonReconciler) Reconcile(ctx context.Context, req ctrl.R
}
}

//TODO: UPDATE
// TODO: UPDATE
return ctrl.Result{}, nil
}

func (r *ObservabilityAddonReconciler) initFinalization(
ctx context.Context, delete bool, hubObsAddon *oav1beta1.ObservabilityAddon,
isHypershift bool) (bool, error) {
isHypershift bool,
) (bool, error) {
if delete && slices.Contains(hubObsAddon.GetFinalizers(), obsAddonFinalizer) {
log.Info("To clean observability components/configurations in the cluster")
err := deleteMetricsCollector(ctx, r.Client, metricsCollectorName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1"
observatoriumv1alpha1 "github.com/stolostron/observatorium-operator/api/v1alpha1"

mcov1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2"
placementctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/controllers/placementrule"
certctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/certificates"
Expand All @@ -52,8 +55,6 @@ import (
"github.com/stolostron/multicluster-observability-operator/operators/pkg/deploying"
commonutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/util"
operatorsutil "github.com/stolostron/multicluster-observability-operator/operators/pkg/util"
mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1"
observatoriumv1alpha1 "github.com/stolostron/observatorium-operator/api/v1alpha1"
)

const (
Expand Down Expand Up @@ -240,22 +241,21 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req
return *result, err
}

//set operand names to cover the upgrade case since we have name changed in new release
// set operand names to cover the upgrade case since we have name changed in new release
err = config.SetOperandNames(r.Client)
if err != nil {
return *result, err
}
//instance.Namespace = config.GetDefaultNamespace()
instance.Spec.StorageConfig.StorageClass = storageClassSelected
//Render the templates with a specified CR
// Render the templates with a specified CR
renderer := rendering.NewMCORenderer(instance, r.Client)
toDeploy, err := renderer.Render()
if err != nil {
reqLogger.Error(err, "Failed to render multiClusterMonitoring templates")
return ctrl.Result{}, err
}
deployer := deploying.NewDeployer(r.Client)
//Deploy the resources
// Deploy the resources
ns := &corev1.Namespace{}
for _, res := range toDeploy {
resNS := res.GetNamespace()
Expand Down Expand Up @@ -363,7 +363,7 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req
isLegacyResourceRemoved = true
}

//update status
// update status
requeueStatusUpdate <- struct{}{}

return ctrl.Result{}, nil
Expand Down
Loading

0 comments on commit 49d7c0b

Please sign in to comment.