-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue-368] knative integration with DataIndex and JobService: fix wo…
…rkflow deletion hanging issue
- Loading branch information
1 parent
b5ad20a
commit 3c59b09
Showing
11 changed files
with
244 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package knative | ||
|
||
import ( | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type MonitoringAvailability struct { | ||
Prometheus bool | ||
Grafana bool | ||
} | ||
|
||
const ( | ||
prometheusGroup = "prometheuses.monitoring.coreos.com" | ||
) | ||
|
||
func GetMonitoringAvailability(cfg *rest.Config) (*MonitoringAvailability, error) { | ||
if cli, err := getDiscoveryClient(cfg); err != nil { | ||
return nil, err | ||
} else { | ||
apiList, err := cli.ServerGroups() | ||
if err != nil { | ||
return nil, err | ||
} | ||
result := new(MonitoringAvailability) | ||
for _, group := range apiList.Groups { | ||
if group.Name == prometheusGroup { | ||
result.Prometheus = true | ||
} | ||
if group.Name == knativeEventingGroup { | ||
result.Grafana = true | ||
} | ||
} | ||
return result, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2024 Apache Software Foundation (ASF) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
|
||
operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08" | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/knative" | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/log" | ||
"k8s.io/klog/v2" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var _ MonitoringEventingHandler = &monitoringObjectManager{} | ||
|
||
type monitoringObjectManager struct { | ||
serviceMonitor ObjectEnsurer | ||
*StateSupport | ||
} | ||
|
||
func NewMonitoringEventingHandler(support *StateSupport) MonitoringEventingHandler { | ||
return &monitoringObjectManager{ | ||
serviceMonitor: NewObjectEnsurer(support.C, ServiceMonitorCreator), | ||
StateSupport: support, | ||
} | ||
} | ||
|
||
type MonitoringEventingHandler interface { | ||
Ensure(ctx context.Context, workflow *operatorapi.SonataFlow) ([]client.Object, error) | ||
} | ||
|
||
func (k monitoringObjectManager) Ensure(ctx context.Context, workflow *operatorapi.SonataFlow) ([]client.Object, error) { | ||
var objs []client.Object | ||
|
||
MonitoringAvail, err := knative.GetMonitoringAvailability(k.Cfg) | ||
if err != nil { | ||
klog.V(log.I).InfoS("Error checking Monitoring Eventing: %v", err) | ||
return nil, err | ||
} | ||
if !MonitoringAvail.Prometheus { | ||
klog.V(log.I).InfoS("Prometheus is not installed") | ||
} else { | ||
// create serviceMonitor | ||
serviceMonitor, _, err := k.serviceMonitor.Ensure(ctx, workflow) | ||
if err != nil { | ||
return objs, err | ||
} else if serviceMonitor != nil { | ||
objs = append(objs, serviceMonitor) | ||
} | ||
/* | ||
triggers := k.trigger.Ensure(ctx, workflow) | ||
for _, trigger := range triggers { | ||
if trigger.Error != nil { | ||
return objs, trigger.Error | ||
} | ||
objs = append(objs, trigger.Object) | ||
} | ||
} | ||
*/ | ||
return objs, nil | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: Prometheus | ||
metadata: | ||
name: prometheus | ||
spec: | ||
serviceAccountName: prometheus | ||
serviceMonitorNamespaceSelector: {} | ||
serviceMonitorSelector: {} | ||
podMonitorSelector: {} | ||
resources: | ||
requests: | ||
memory: 400Mi | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: prometheus | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: prometheus | ||
rules: | ||
- apiGroups: [""] | ||
resources: | ||
- nodes | ||
- nodes/metrics | ||
- services | ||
- endpoints | ||
- pods | ||
verbs: ["get", "list", "watch"] | ||
- apiGroups: [""] | ||
resources: | ||
- configmaps | ||
verbs: ["get"] | ||
- apiGroups: | ||
- networking.k8s.io | ||
resources: | ||
- ingresses | ||
verbs: ["get", "list", "watch"] | ||
- nonResourceURLs: ["/metrics"] | ||
verbs: ["get"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: prometheus | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: prometheus | ||
subjects: | ||
- kind: ServiceAccount | ||
name: prometheus | ||
namespace: default |