Skip to content

Commit

Permalink
Add role
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoseangel committed Aug 29, 2020
1 parent 685d396 commit ef3a22f
Show file tree
Hide file tree
Showing 20 changed files with 272 additions and 1 deletion.
4 changes: 4 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
domain: example.com
layout: ansible.sdk.operatorframework.io/v1
projectName: k8s-operator
resources:
- group: apps
kind: AppService
version: v1alpha1
version: 3-alpha
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $ operator-sdk create api --group apps --version v1alpha1 --kind AppService --ge

### Define the API

This command specifies that the CRD will be called **AppService** and creates the file **api/v1/presentation_types.go**, which you can modify to specify the input parameter of your CRD. For this example application, you need only one parameter, called **Markdown**:
This command specifies that the CRD will be called **AppService** and creates the role **roles/appservice**, which you can modify to specify the input parameter of your CRD:

```go
// PresentationSpec defines the desired state of Presentation
Expand Down
44 changes: 44 additions & 0 deletions config/crd/bases/apps.example.com_appservices.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: appservices.apps.example.com
spec:
group: apps.example.com
names:
kind: AppService
listKind: AppServiceList
plural: appservices
singular: appservice
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: AppService is the Schema for the appservices API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec defines the desired state of AppService
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: Status defines the observed state of AppService
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
served: true
storage: true
subresources:
status: {}
6 changes: 6 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/apps.example.com_appservices.yaml
# +kubebuilder:scaffold:crdkustomizeresource
24 changes: 24 additions & 0 deletions config/rbac/appservice_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit appservices.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: appservice-editor-role
rules:
- apiGroups:
- apps.example.com
resources:
- appservices
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps.example.com
resources:
- appservices/status
verbs:
- get
20 changes: 20 additions & 0 deletions config/rbac/appservice_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# permissions for end users to view appservices.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: appservice-viewer-role
rules:
- apiGroups:
- apps.example.com
resources:
- appservices
verbs:
- get
- list
- watch
- apiGroups:
- apps.example.com
resources:
- appservices/status
verbs:
- get
16 changes: 16 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,20 @@ rules:
- patch
- update
- watch
##
## Rules for apps.example.com/v1alpha1, Kind: AppService
##
- apiGroups:
- apps.example.com
resources:
- appservices
- appservices/status
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
# +kubebuilder:scaffold:rules
6 changes: 6 additions & 0 deletions config/samples/apps_v1alpha1_appservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: apps.example.com/v1alpha1
kind: AppService
metadata:
name: appservice-sample
spec:
foo: bar
4 changes: 4 additions & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Append samples you want in your CSV to this file as resources ##
resources:
- apps_v1alpha1_appservice.yaml
# +kubebuilder:scaffold:manifestskustomizesamples
19 changes: 19 additions & 0 deletions molecule/default/tasks/appservice_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Create the apps.example.com/v1alpha1.AppService
k8s:
state: present
namespace: '{{ namespace }}'
definition: "{{ lookup('template', '/'.join([samples_dir, cr_file])) | from_yaml }}"
wait: yes
wait_timeout: 300
wait_condition:
type: Running
reason: Successful
status: "True"
vars:
cr_file: 'apps_v1alpha1_appservice.yaml'

- name: Add assertions here
assert:
that: false
fail_msg: FIXME Add real assertions for your operator
9 changes: 9 additions & 0 deletions playbooks/appservice.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- hosts: localhost
gather_facts: no
collections:
- community.kubernetes
- operator_sdk.util
tasks:
- import_role:
name: "appservice"
43 changes: 43 additions & 0 deletions roles/appservice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance,
if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in
defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables
that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set
for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for
users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
2 changes: 2 additions & 0 deletions roles/appservice/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for AppService
Empty file.
2 changes: 2 additions & 0 deletions roles/appservice/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for AppService
64 changes: 64 additions & 0 deletions roles/appservice/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
galaxy_info:
author: your name
description: your description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http:https://example.com/issue/tracker

# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)

min_ansible_version: 2.9

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
collections:
- operator_sdk.util
- community.kubernetes
2 changes: 2 additions & 0 deletions roles/appservice/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# tasks file for AppService
Empty file.
2 changes: 2 additions & 0 deletions roles/appservice/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for AppService
4 changes: 4 additions & 0 deletions watches.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
# Use the 'create api' subcommand to add watches to this file.
- version: v1alpha1
group: apps.example.com
kind: AppService
playbook: playbooks/appservice.yml
# +kubebuilder:scaffold:watch

0 comments on commit ef3a22f

Please sign in to comment.