Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. // +kubebuilder:rbac:groups=stable.resource.operator.io,resources=resource,verbs=get;list;watch;create;update;patch;delete
  2. // +kubebuilder:rbac:groups=stable.resource.operator.io,resources=resource/status,verbs=get;update;patch
  3. // +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
  4. // +kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get;list;watch;create;update;patch;delete
  5. func (r *ResourceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
  6.  
  7. ctx := context.Background()
  8. log := r.Log.WithValues("resource", req.NamespacedName)
  9. instance := &stablev1.Resource{}
  10. // your logic here
  11.  
  12. if err := r.Get(ctx, req.NamespacedName, instance); err != nil {
  13. log.Error(err, "unable to fetch Resource")
  14. // we'll ignore not-found errors, since they can't be fixed by an immediate
  15. // requeue (we'll need to wait for a new notification), and we can get them
  16. // on deleted requests.
  17. return ctrl.Result{}, ignoreNotFound(err)
  18. }
  19. // your logic here
  20. u := &unstructured.Unstructured{}
  21. u.Object = map[string]interface{}{
  22. "name": "name",
  23. "namespace": "namespace",
  24. "spec": map[string]interface{}{
  25. "replicas": 2,
  26. "selector": map[string]interface{}{
  27. "matchLabels": map[string]interface{}{
  28. "foo": "bar",
  29. },
  30. },
  31. "template": map[string]interface{}{
  32. "labels": map[string]interface{}{
  33. "foo": "bar",
  34. },
  35. "spec": map[string]interface{}{
  36. "containers": []map[string]interface{}{
  37. {
  38. "name": "nginx",
  39. "image": "nginx",
  40. },
  41. },
  42. },
  43. },
  44. },
  45. }
  46. u.SetGroupVersionKind(schema.GroupVersionKind{
  47. Group: "apps",
  48. Kind: "Deployment",
  49. Version: "v1",
  50. })
  51. err = r.Create(context.Background(), u)
  52. log.Error(err, "unable to get object")
  53. log.V(1).Info("reconciling")
  54. return ctrl.Result{}, nil
  55.  
  56. }
  57.  
  58. the server does not allow this method on the requested resource
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement