-
Notifications
You must be signed in to change notification settings - Fork 40
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
✨ support config work driver. #256
Merged
openshift-merge-bot
merged 6 commits into
open-cluster-management-io:main
from
morvencao:br_add_work_driver
Apr 19, 2024
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
da0d4f9
support cloudevents driver for addon manager.
morvencao d8d4f52
remove e2e testing for cloudevents.
morvencao 5c1a6e7
revert addon manager interface change.
morvencao 7ad6107
add base addon manager.
morvencao a7bac3b
address comments.
morvencao c7ba5b9
add e2e test back.
morvencao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: CloudEventsIntegration | ||
|
||
on: | ||
workflow_dispatch: {} | ||
pull_request: | ||
paths: | ||
- 'pkg/addonmanager/cloudevents/*.go' | ||
- 'test/integration/cloudevents/**' | ||
branches: | ||
- main | ||
- release-* | ||
|
||
env: | ||
GO_VERSION: '1.21' | ||
GO_REQUIRED_MIN_VERSION: '' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
integration: | ||
name: cloudevents-integration | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout code | ||
uses: actions/checkout@v4 | ||
- name: install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: integration | ||
run: make test-cloudevents-integration |
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,145 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
goflag "flag" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
utilrand "k8s.io/apimachinery/pkg/util/rand" | ||
"k8s.io/client-go/rest" | ||
utilflag "k8s.io/component-base/cli/flag" | ||
logs "k8s.io/component-base/logs" | ||
"k8s.io/klog/v2" | ||
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned" | ||
|
||
"open-cluster-management.io/addon-framework/examples/helloworld_agent" | ||
"open-cluster-management.io/addon-framework/examples/helloworld_cloudevents" | ||
"open-cluster-management.io/addon-framework/pkg/addonfactory" | ||
"open-cluster-management.io/addon-framework/pkg/addonmanager/cloudevents" | ||
cmdfactory "open-cluster-management.io/addon-framework/pkg/cmd/factory" | ||
"open-cluster-management.io/addon-framework/pkg/utils" | ||
"open-cluster-management.io/addon-framework/pkg/version" | ||
) | ||
|
||
func main() { | ||
rand.Seed(time.Now().UTC().UnixNano()) | ||
|
||
pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc) | ||
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) | ||
|
||
logs.AddFlags(pflag.CommandLine) | ||
logs.InitLogs() | ||
defer logs.FlushLogs() | ||
|
||
command := newCommand() | ||
if err := command.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "%v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func newCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "addon", | ||
Short: "helloworld example addon", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cmd.Help(); err != nil { | ||
fmt.Fprintf(os.Stderr, "%v\n", err) | ||
} | ||
os.Exit(1) | ||
}, | ||
} | ||
|
||
if v := version.Get().String(); len(v) == 0 { | ||
cmd.Version = "<unknown>" | ||
} else { | ||
cmd.Version = v | ||
} | ||
|
||
cmd.AddCommand(newControllerCommand()) | ||
cmd.AddCommand(helloworld_agent.NewAgentCommand(helloworld_cloudevents.AddonName)) | ||
|
||
return cmd | ||
} | ||
|
||
func newControllerCommand() *cobra.Command { | ||
o := cloudevents.NewCloudEventsOptions() | ||
c := &addManagerConfig{cloudeventsOptions: o} | ||
cmd := cmdfactory. | ||
NewControllerCommandConfig("helloworld-addon-controller", version.Get(), c.runController). | ||
NewCommand() | ||
cmd.Use = "controller" | ||
cmd.Short = "Start the addon controller with cloudevents" | ||
o.AddFlags(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// addManagerConfig holds cloudevents configuration for addon manager | ||
type addManagerConfig struct { | ||
cloudeventsOptions *cloudevents.CloudEventsOptions | ||
} | ||
|
||
func (c *addManagerConfig) runController(ctx context.Context, kubeConfig *rest.Config) error { | ||
addonClient, err := addonv1alpha1client.NewForConfig(kubeConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mgr, err := cloudevents.New(kubeConfig, c.cloudeventsOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
registrationOption := helloworld_cloudevents.NewRegistrationOption( | ||
kubeConfig, | ||
helloworld_cloudevents.AddonName, | ||
utilrand.String(5), | ||
) | ||
|
||
// Set agent install namespace from addon deployment config if it exists | ||
registrationOption.AgentInstallNamespace = utils.AgentInstallNamespaceFromDeploymentConfigFunc( | ||
utils.NewAddOnDeploymentConfigGetter(addonClient), | ||
) | ||
|
||
agentAddon, err := addonfactory.NewAgentAddonFactory(helloworld_cloudevents.AddonName, helloworld_cloudevents.FS, "manifests/templates"). | ||
WithConfigGVRs(utils.AddOnDeploymentConfigGVR). | ||
WithGetValuesFuncs( | ||
helloworld_cloudevents.GetDefaultValues, | ||
addonfactory.GetAddOnDeploymentConfigValues( | ||
utils.NewAddOnDeploymentConfigGetter(addonClient), | ||
addonfactory.ToAddOnDeploymentConfigValues, | ||
addonfactory.ToImageOverrideValuesFunc("Image", helloworld_cloudevents.DefaultImage), | ||
), | ||
). | ||
WithAgentRegistrationOption(registrationOption). | ||
WithAgentInstallNamespace( | ||
utils.AgentInstallNamespaceFromDeploymentConfigFunc( | ||
utils.NewAddOnDeploymentConfigGetter(addonClient), | ||
), | ||
). | ||
WithAgentHealthProber(helloworld_cloudevents.AgentHealthProber()). | ||
BuildTemplateAgentAddon() | ||
if err != nil { | ||
klog.Errorf("failed to build agent %v", err) | ||
return err | ||
} | ||
|
||
err = mgr.AddAgent(agentAddon) | ||
if err != nil { | ||
klog.Fatal(err) | ||
} | ||
|
||
err = mgr.Start(ctx) | ||
if err != nil { | ||
klog.Fatal(err) | ||
} | ||
<-ctx.Done() | ||
|
||
return nil | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/deploy/addon/helloworld-cloudevents/kustomization.yaml
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,28 @@ | ||
namespace: open-cluster-management | ||
|
||
resources: | ||
- resources/cluster_role.yaml | ||
- resources/cluster_role_binding.yaml | ||
- resources/service_account.yaml | ||
- resources/managed_clusterset_binding.yaml | ||
- resources/placement.yaml | ||
- resources/addon_deployment_config.yaml | ||
- resources/helloworld_cloudevents_clustermanagementaddon.yaml | ||
- resources/helloworld_cloudevents_controller.yaml | ||
- resources/work-driver-config.yaml | ||
|
||
images: | ||
- name: quay.io/open-cluster-management/addon-examples | ||
newName: quay.io/open-cluster-management/addon-examples | ||
newTag: latest | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
vars: | ||
- name: EXAMPLE_IMAGE_NAME | ||
objref: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: helloworldcloudevents-controller | ||
fieldref: | ||
fieldpath: spec.template.spec.containers.[name=helloworldcloudevents-controller].image |
6 changes: 6 additions & 0 deletions
6
examples/deploy/addon/helloworld-cloudevents/resources/addon_deployment_config.yaml
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,6 @@ | ||
apiVersion: addon.open-cluster-management.io/v1alpha1 | ||
kind: AddOnDeploymentConfig | ||
metadata: | ||
name: global | ||
spec: | ||
agentInstallNamespace: open-cluster-management-agent-addon |
50 changes: 50 additions & 0 deletions
50
examples/deploy/addon/helloworld-cloudevents/resources/cluster_role.yaml
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,50 @@ | ||
kind: ClusterRole | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: helloworldcloudevents-addon | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["configmaps", "events"] | ||
verbs: ["get", "list", "watch", "create", "update", "delete", "deletecollection", "patch"] | ||
- apiGroups: ["coordination.k8s.io"] | ||
resources: ["leases"] | ||
verbs: ["get", "list", "watch", "create", "update", "patch"] | ||
- apiGroups: ["rbac.authorization.k8s.io"] | ||
resources: ["roles", "rolebindings"] | ||
verbs: ["get", "list", "watch", "create", "update", "delete"] | ||
- apiGroups: ["authorization.k8s.io"] | ||
resources: ["subjectaccessreviews"] | ||
verbs: ["get", "create"] | ||
- apiGroups: ["certificates.k8s.io"] | ||
resources: ["certificatesigningrequests", "certificatesigningrequests/approval"] | ||
verbs: ["get", "list", "watch", "create", "update"] | ||
- apiGroups: ["certificates.k8s.io"] | ||
resources: ["signers"] | ||
verbs: ["approve"] | ||
- apiGroups: ["cluster.open-cluster-management.io"] | ||
resources: ["managedclusters"] | ||
verbs: ["get", "list", "watch"] | ||
- apiGroups: ["work.open-cluster-management.io"] | ||
resources: ["manifestworks"] | ||
verbs: ["create", "update", "get", "list", "watch", "delete", "deletecollection", "patch"] | ||
- apiGroups: ["addon.open-cluster-management.io"] | ||
resources: ["managedclusteraddons/finalizers"] | ||
verbs: ["update"] | ||
- apiGroups: [ "addon.open-cluster-management.io" ] | ||
resources: [ "clustermanagementaddons/finalizers" ] | ||
verbs: [ "update" ] | ||
- apiGroups: [ "addon.open-cluster-management.io" ] | ||
resources: [ "clustermanagementaddons/status" ] | ||
verbs: ["update", "patch"] | ||
- apiGroups: ["addon.open-cluster-management.io"] | ||
resources: ["clustermanagementaddons"] | ||
verbs: ["get", "list", "watch", "patch"] | ||
- apiGroups: ["addon.open-cluster-management.io"] | ||
resources: ["managedclusteraddons"] | ||
verbs: ["get", "list", "watch", "create", "update", "delete"] | ||
- apiGroups: ["addon.open-cluster-management.io"] | ||
resources: ["managedclusteraddons/status"] | ||
verbs: ["update", "patch"] | ||
- apiGroups: ["addon.open-cluster-management.io"] | ||
resources: ["addondeploymentconfigs"] | ||
verbs: ["get", "list", "watch"] |
12 changes: 12 additions & 0 deletions
12
examples/deploy/addon/helloworld-cloudevents/resources/cluster_role_binding.yaml
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,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: helloworldcloudevents-addon | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: helloworldcloudevents-addon | ||
subjects: | ||
- kind: ServiceAccount | ||
name: helloworldcloudevents-addon-sa | ||
namespace: open-cluster-management |
21 changes: 21 additions & 0 deletions
21
...addon/helloworld-cloudevents/resources/helloworld_cloudevents_clustermanagementaddon.yaml
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,21 @@ | ||
apiVersion: addon.open-cluster-management.io/v1alpha1 | ||
kind: ClusterManagementAddOn | ||
metadata: | ||
name: helloworldcloudevents | ||
spec: | ||
addOnMeta: | ||
displayName: helloworldcloudevents | ||
description: "helloworldcloudevents is an example addon using cloudevents created by go template" | ||
supportedConfigs: | ||
- group: addon.open-cluster-management.io | ||
resource: addondeploymentconfigs | ||
installStrategy: | ||
type: Placements | ||
placements: | ||
- name: global | ||
namespace: open-cluster-management | ||
configs: | ||
- group: addon.open-cluster-management.io | ||
resource: addondeploymentconfigs | ||
name: global | ||
namespace: open-cluster-management |
43 changes: 43 additions & 0 deletions
43
...ples/deploy/addon/helloworld-cloudevents/resources/helloworld_cloudevents_controller.yaml
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,43 @@ | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: helloworldcloudevents-controller | ||
labels: | ||
app: helloworldcloudevents-controller | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: helloworldcloudevents-controller | ||
template: | ||
metadata: | ||
labels: | ||
app: helloworldcloudevents-controller | ||
spec: | ||
serviceAccountName: helloworldcloudevents-addon-sa | ||
containers: | ||
- name: helloworldcloudevents-controller | ||
image: quay.io/open-cluster-management/addon-examples | ||
imagePullPolicy: IfNotPresent | ||
env: | ||
- name: EXAMPLE_IMAGE_NAME | ||
value: $(EXAMPLE_IMAGE_NAME) | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
args: | ||
- "/helloworld_cloudevents" | ||
- "controller" | ||
- "--work-driver=mqtt" | ||
- "--work-driver-config=/var/run/secrets/hub/config.yaml" | ||
- "--cloudevents-client-id=addon-manager-$(POD_NAME)" | ||
- "--source-id=addon-manager" | ||
volumeMounts: | ||
- mountPath: /var/run/secrets/hub | ||
name: workdriverconfig | ||
readOnly: true | ||
volumes: | ||
- name: workdriverconfig | ||
secret: | ||
secretName: work-driver-config |
6 changes: 6 additions & 0 deletions
6
examples/deploy/addon/helloworld-cloudevents/resources/managed_clusterset_binding.yaml
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,6 @@ | ||
apiVersion: cluster.open-cluster-management.io/v1beta2 | ||
kind: ManagedClusterSetBinding | ||
metadata: | ||
name: global | ||
spec: | ||
clusterSet: global |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also add an e2e to at least check that the example cloud event addons are available when deploying into a kubernetes cluster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e2e test was removed in this commit: d8d4f52
because the work client based on cloudevents drivers (sdk-go) are missing GC machnism, we will revisit and add e2e after GC machnism support for cloudevents drivers.