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

fixup the operator-sdk bundle #19

Merged
merged 2 commits into from
Jun 18, 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
1 change: 1 addition & 0 deletions Containerfile.bpfman-operator
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ARG TARGETARCH
WORKDIR /
COPY --from=bpfman-operator-build /usr/src/bpfman-operator/config/bpfman-deployment/daemonset.yaml ./config/bpfman-deployment/daemonset.yaml
COPY --from=bpfman-operator-build /usr/src/bpfman-operator/config/bpfman-deployment/csidriverinfo.yaml ./config/bpfman-deployment/csidriverinfo.yaml
COPY --from=bpfman-operator-build /usr/src/bpfman-operator/config/openshift/restricted-scc.yaml ./config/openshift/restricted-scc.yaml
COPY --from=bpfman-operator-build /usr/src/bpfman-operator/bpfman-operator .
USER 65532:65532

Expand Down
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,10 @@ make undeploy-openshift
The other option for installing the `bpfman-operator` is through the
[OLM bundle](https://www.redhat.com/en/blog/deploying-operators-olm-bundles).

First create the namespace:
Use `operator-sdk` to install the bundle like so:

```bash
oc create ns openshift-bpfman
```

Then use `operator-sdk` to install the bundle like so:

```bash
operator-sdk run bundle quay.io/bpfman/bpfman-operator-bundle:latest --namespace openshift-bpfman
operator-sdk run bundle quay.io/bpfman/bpfman-operator-bundle:latest --namespace bpfman
```

To clean up at a later time, execute:
Expand All @@ -78,12 +72,6 @@ To clean up at a later time, execute:
operator-sdk cleanup bpfman-operator
```

followed by

```bash
oc delete ns openshift-bpfman
```

## Verify the Installation

Regardless of the deployment method, if the `bpfman-operator` was deployed successfully,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: bpfman-daemon
namespace: openshift-bpfman
namespace: bpfman
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: bpfman-daemon
namespace: openshift-bpfman
namespace: bpfman
59 changes: 42 additions & 17 deletions bundle/manifests/bpfman-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,25 @@ metadata:
}
]
capabilities: Basic Install
categories: OpenShift Optional
containerImage: quay.io/bpfman/bpfman-operator:v0.0.0
createdAt: "2024-06-04T18:15:26Z"
createdAt: "2024-06-07T18:48:53Z"
operatorframework.io/suggested-namespace-template: |-
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "bpfman",
"labels": {
"pod-security.kubernetes.io/enforce": "privileged",
"pod-security.kubernetes.io/audit": "privileged",
"pod-security.kubernetes.io/warn": "privileged",
},
"annotations": {
"openshift.io/node-selector": ""
},
}
}
operators.operatorframework.io/builder: operator-sdk-v1.27.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/bpfman/bpfman
Expand Down Expand Up @@ -268,22 +285,20 @@ spec:
description: "The bpfman Operator is a Kubernetes Operator for deploying [bpfman](https://bpfman.netlify.app/),
a system daemon\nfor managing eBPF programs. It deploys bpfman itself along with
CRDs to make deploying\neBPF programs in Kubernetes much easier.\n\n## Quick Start\n\nTo
get bpfman up and running quickly with self signed certificates simply do \nthe
following.\n\n```bash\nkubectl create namespace openshift-bpfman\n```\n After
creating the namespace simply install the bpfman-operator in the desired namespace
from operator-hub\n## Configuration\n\nThe `bpfman-config` configmap is automatically
created in the `bpfman` namespace and used to configure the bpfman deployment.\n\nTo
edit the config simply run\n\n```bash\nkubectl edit cm bpfman-config\n```\n\nThe
following fields are adjustable\n\n- `bpfman.agent.image`: The image used for
the bpfman-agent, defaults to `quay.io/bpfman/bpfman-agent:latest`\n- `bpfman.image`:
The image used for bpfman, defaults to `quay.io/bpfman/bpfman:latest`\n- `bpfman.log.level`:
the log level for bpfman, currently supports `debug`, `info`, `warn`, `error`,
and `fatal`, defaults to `info`\n- `bpfman.agent.log.level`: the log level for
the bpfman-agent currently supports `info`, `debug`, and `trace` \n\nThe bpfman
operator deploys eBPF programs via CRDs. The following CRDs are currently available,
\n\n- XdpProgram\n- TcProgram\n- TracepointProgram\n- KprobeProgram\n- UprobeProgram\n-
FentryProgram\n- FexitProgram\n\n## More information\n\nPlease checkout the [bpfman
community website](https://bpfman.io/) for more information."
get bpfman up and running quickly simply click 'install' to deploy the bpfman-operator
in the bpfman namespace via operator-hub.\n## Configuration\n\nThe `bpfman-config`
configmap is automatically created in the `bpfman` namespace and used to configure
the bpfman deployment.\n\nTo edit the config simply run\n\n```bash\nkubectl edit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the bundle more OCP specific? If so, should kubectl be replaced with oc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So technically the operatorhub is for everyone, and community operators prod is for OCP I think we can leave it as kubectl here and add a carry commit to https://github.com/redhat-openshift-ecosystem/community-operators-prod

cm bpfman-config\n```\n\nThe following fields are adjustable\n\n- `bpfman.agent.image`:
The image used for the bpfman-agent, defaults to `quay.io/bpfman/bpfman-agent:latest`\n-
`bpfman.image`: The image used for bpfman, defaults to `quay.io/bpfman/bpfman:latest`\n-
`bpfman.log.level`: the log level for bpfman, currently supports `debug`, `info`,
`warn`, `error`, and `fatal`, defaults to `info`\n- `bpfman.agent.log.level`:
the log level for the bpfman-agent currently supports `info`, `debug`, and `trace`
\n\nThe bpfman operator deploys eBPF programs via CRDs. The following CRDs are
currently available, \n\n- XdpProgram\n- TcProgram\n- TracepointProgram\n- KprobeProgram\n-
UprobeProgram\n- FentryProgram\n- FexitProgram\n\n## More information\n\nPlease
checkout the [bpfman community website](https://bpfman.io/) for more information."
displayName: Bpfman Operator
icon:
- base64data: |
Expand Down Expand Up @@ -814,6 +829,16 @@ spec:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
- securitycontextconstraints
verbs:
- create
- delete
- get
- list
- watch
- apiGroups:
- storage.k8s.io
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: bpfman-daemon
namespace: openshift-bpfman
namespace: bpfman
44 changes: 44 additions & 0 deletions cmd/bpfman-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
bpfmanoperator "github.com/bpfman/bpfman-operator/controllers/bpfman-operator"
"github.com/bpfman/bpfman-operator/internal"

osv1 "github.com/openshift/api/security/v1"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/discovery"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -46,9 +49,34 @@
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(bpfmaniov1alpha1.Install(scheme))
utilruntime.Must(osv1.Install(scheme))

Check warning on line 52 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L52

Added line #L52 was not covered by tests
//+kubebuilder:scaffold:scheme
}

// Returns true if the current platform is Openshift.
func isOpenshift(client discovery.DiscoveryInterface, cfg *rest.Config) (bool, error) {
k8sVersion, err := client.ServerVersion()
if err != nil {
setupLog.Info("issue occurred while fetching ServerVersion")
return false, err
}

Check warning on line 62 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L57-L62

Added lines #L57 - L62 were not covered by tests

setupLog.Info("detected platform version", "PlatformVersion", k8sVersion)
apiList, err := client.ServerGroups()
if err != nil {
setupLog.Info("issue occurred while fetching ServerGroups")
return false, err
}

Check warning on line 69 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L64-L69

Added lines #L64 - L69 were not covered by tests

for _, v := range apiList.Groups {
if v.Name == "route.openshift.io" {
setupLog.Info("route.openshift.io found in apis, platform is OpenShift")
return true, nil
}

Check warning on line 75 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L71-L75

Added lines #L71 - L75 were not covered by tests
}
return false, nil

Check warning on line 77 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L77

Added line #L77 was not covered by tests
}

func main() {
var metricsAddr string
var enableLeaderElection bool
Expand Down Expand Up @@ -129,10 +157,26 @@
Scheme: mgr.GetScheme(),
}

setupLog.Info("Discovering APIs")
dc, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "can't instantiate discovery client")
os.Exit(1)
}

Check warning on line 165 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L160-L165

Added lines #L160 - L165 were not covered by tests

isOpenshift, err := isOpenshift(dc, mgr.GetConfig())
if err != nil {
setupLog.Error(err, "unable to determine platform")
os.Exit(1)
Billy99 marked this conversation as resolved.
Show resolved Hide resolved

}

Check warning on line 172 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L167-L172

Added lines #L167 - L172 were not covered by tests

if err = (&bpfmanoperator.BpfmanConfigReconciler{
ReconcilerCommon: common,
BpfmanStandardDeployment: internal.BpfmanDaemonManifestPath,
CsiDriverDeployment: internal.BpfmanCsiDriverPath,
RestrictedSCC: internal.BpfmanRestrictedSCCPath,
IsOpenshift: isOpenshift,

Check warning on line 179 in cmd/bpfman-operator/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/bpfman-operator/main.go#L178-L179

Added lines #L178 - L179 were not covered by tests
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create bpfmanCofig controller", "controller", "BpfProgram")
os.Exit(1)
Expand Down
22 changes: 19 additions & 3 deletions config/manifests/bases/bpfman-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,26 @@ kind: ClusterServiceVersion
metadata:
annotations:
alm-examples: "[]"
categories: OpenShift Optional
capabilities: Basic Install
containerImage: quay.io/bpfman/bpfman-operator:v0.0.0
repository: https://github.com/bpfman/bpfman
operatorframework.io/suggested-namespace-template: |-
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "bpfman",
"labels": {
"pod-security.kubernetes.io/enforce": "privileged",
"pod-security.kubernetes.io/audit": "privileged",
"pod-security.kubernetes.io/warn": "privileged",
},
"annotations": {
"openshift.io/node-selector": ""
},
}
}
name: bpfman-operator.v0.0.0
namespace: placeholder
spec:
Expand Down Expand Up @@ -56,9 +73,8 @@ spec:
"The bpfman Operator is a Kubernetes Operator for deploying [bpfman](https://bpfman.netlify.app/),
a system daemon\nfor managing eBPF programs. It deploys bpfman itself along with
CRDs to make deploying\neBPF programs in Kubernetes much easier.\n\n##
Quick Start\n\nTo get bpfman up and running quickly with self signed certificates
simply do \nthe following.\n\n```bash\nkubectl create namespace openshift-bpfman\n```\n After creating the namespace simply install
the bpfman-operator in the desired namespace from operator-hub\n##
Quick Start\n\nTo get bpfman up and running quickly simply click 'install'
to deploy the bpfman-operator in the bpfman namespace via operator-hub.\n##
Configuration\n\nThe `bpfman-config` configmap is automatically created in the `bpfman`
namespace and used to configure the bpfman deployment.\n\nTo edit the config simply
run\n\n```bash\nkubectl edit cm bpfman-config\n```\n\nThe following fields are adjustable\n\n-
Expand Down
3 changes: 1 addition & 2 deletions config/openshift/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Adds namespace to all resources.
namespace: openshift-bpfman
namespace: bpfman

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
Expand Down Expand Up @@ -33,4 +33,3 @@ resources:
- ../bpfman-operator-deployment
- ../bpfman-deployment
- rbac.yaml
- user-scc.yaml
16 changes: 15 additions & 1 deletion config/openshift/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ roleRef:
subjects:
- kind: ServiceAccount
name: bpfman-daemon
namespace: openshift-bpfman
namespace: bpfman
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: user
rules:
- apiGroups:
- security.openshift.io
resourceNames:
- bpfman-restricted
resources:
- securitycontextconstraints
verbs:
- use
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
## This is part of the payload deployed by the bpfman-operator NOT kustomize.
apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints
metadata:
name: restricted
name: bpfman-restricted
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
Expand All @@ -18,7 +19,7 @@ readOnlyRootFilesystem: false
requiredDropCapabilities:
- ALL
runAsUser:
type: RunAsAny
type: MustRunAsNonRoot
seLinuxContext:
type: RunAsAny
seccompProfiles: null
Expand All @@ -35,18 +36,3 @@ volumes:
- persistentVolumeClaim
- projected
- secret
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: user
rules:
- apiGroups:
- security.openshift.io
resourceNames:
- bpfman-restricted
resources:
- securitycontextconstraints
verbs:
- use
---
10 changes: 10 additions & 0 deletions config/rbac/bpfman-operator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ rules:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
- securitycontextconstraints
verbs:
- create
- delete
- get
- list
- watch
- apiGroups:
- storage.k8s.io
resources:
Expand Down
Loading
Loading