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

FIX: Incorrect api endpoints and kube client methods #77

Merged
merged 1 commit into from
Sep 9, 2021
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
6 changes: 3 additions & 3 deletions internal/crd/v1alpha1/permissionmanageruser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package v1alpha1
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

const (
ResourceURL = "apis/permissionmanager.PermissionManagerUser/v1alpha1/permissionmanagerusers"
ResourcePrefix = "permissionmanager.PermissionManagerUser."
ResourceURL = "apis/permissionmanager.user/v1alpha1/permissionmanagerusers"
ResourcePrefix = "permissionmanagerusers.permissionmanager.user."
)

type PermissionManagerUserSpec struct {
Expand All @@ -21,5 +21,5 @@ type PermissionManagerUser struct {
type PermissionManagerUserList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PermissionManagerUser `json:"items"`
Items []PermissionManagerUser `json:"items"`
}
13 changes: 7 additions & 6 deletions internal/resources/v1alpha1_permissionmanageruser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package resources
import (
"context"
"encoding/json"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sclient "k8s.io/client-go/kubernetes"
"log"
"sighupio/permission-manager/internal/crd/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sclient "k8s.io/client-go/kubernetes"
)

type V1Alpha1PermissionManagerUser struct {
Expand All @@ -24,7 +25,7 @@ func (r *V1Alpha1PermissionManagerUser) List() ([]User, error) {
//noinspection GoPreferNilSlice
users := []User{}

rawResponse, err := r.kubeclient.AppsV1().RESTClient().Get().AbsPath(v1alpha1.ResourceURL).DoRaw(r.context)
rawResponse, err := r.kubeclient.Discovery().RESTClient().Get().AbsPath(v1alpha1.ResourceURL).DoRaw(r.context)

if err != nil {
log.Print("Failed to get users from k8s CRUD api", err)
Expand Down Expand Up @@ -54,7 +55,7 @@ func (r *V1Alpha1PermissionManagerUser) Create(username string) (User, error) {

createUserRequest := v1alpha1.PermissionManagerUser{
TypeMeta: metav1.TypeMeta{
APIVersion: "permissionmanager.PermissionManagerUser/v1alpha1",
APIVersion: "permissionmanager.user/v1alpha1",
Kind: "Permissionmanageruser",
},
Metadata: metav1.ObjectMeta{
Expand All @@ -71,7 +72,7 @@ func (r *V1Alpha1PermissionManagerUser) Create(username string) (User, error) {
return User{}, err
}

_, err = r.kubeclient.AppsV1().RESTClient().Post().AbsPath(v1alpha1.ResourceURL).Body([]byte(jsonPayload)).DoRaw(r.context)
_, err = r.kubeclient.Discovery().RESTClient().Post().AbsPath(v1alpha1.ResourceURL).Body(jsonPayload).DoRaw(r.context)

if err != nil {
log.Printf("Failed to create PermissionManagerUser:%s\n %v\n", username, err)
Expand All @@ -86,7 +87,7 @@ func (r *V1Alpha1PermissionManagerUser) Create(username string) (User, error) {
func (r *V1Alpha1PermissionManagerUser) Delete(username string) error {
metadataName := v1alpha1.ResourcePrefix + username

_, err := r.kubeclient.AppsV1().RESTClient().Delete().AbsPath(v1alpha1.ResourceURL + "/" + metadataName).DoRaw(r.context)
_, err := r.kubeclient.Discovery().RESTClient().Delete().AbsPath(v1alpha1.ResourceURL + "/" + metadataName).DoRaw(r.context)

if err == nil {
return nil
Expand Down