-
Notifications
You must be signed in to change notification settings - Fork 184
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
extend the onboarding struct to make it modular #2791
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
package services | ||
|
||
type OnboardingSubjectRole string | ||
|
||
type OnboardingSubjectRoleSpec struct { | ||
Role OnboardingSubjectRole `json:"role"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are trying to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ClientOptions ClientRoleOptions `json:"clientRoleOptions,omitempty"` | ||
} | ||
|
||
const ( | ||
ClientRole OnboardingSubjectRole = "ocs-client" | ||
) | ||
|
||
type ClientRoleOptions struct { | ||
StorageQuotaInGiB uint `json:"storageQuotaInGiB,omitempty"` | ||
} | ||
|
||
type OnboardingTicket struct { | ||
ID string `json:"id"` | ||
ExpirationDate int64 `json:"expirationDate,string"` | ||
StorageQuotaInGiB uint `json:"storageQuotaInGiB,omitempty"` | ||
ID string `json:"id"` | ||
ExpirationDate int64 `json:"expirationDate,string"` | ||
|
||
// SubjectRole specifies the role and options for the role | ||
SubjectRole OnboardingSubjectRoleSpec `json:"subjectRole"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ import ( | |
"net/http" | ||
|
||
"github.com/red-hat-storage/ocs-operator/v4/controllers/util" | ||
"github.com/red-hat-storage/ocs-operator/v4/services" | ||
"github.com/red-hat-storage/ocs-operator/v4/services/ux-backend/handlers" | ||
|
||
"k8s.io/klog/v2" | ||
"k8s.io/utils/ptr" | ||
) | ||
|
||
const ( | ||
|
@@ -32,9 +33,9 @@ func HandleMessage(w http.ResponseWriter, r *http.Request, tokenLifetimeInHours | |
} | ||
|
||
func handlePost(w http.ResponseWriter, r *http.Request, tokenLifetimeInHours int) { | ||
var storageQuotaInGiB *uint | ||
// When ContentLength is 0 that means request body is empty and | ||
// storage quota is unlimited | ||
|
||
var roleSpec services.OnboardingSubjectRoleSpec | ||
roleSpec.Role = services.ClientRole | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setting fields at multiple places forces us to look for where all these are set, better to move this to line 59 only where you are setting the options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we have only one role up to this point, I am always setting the role as clientRole to avoid further changes to console. With 4.18, we will explicitly set the role while calling this endpoint |
||
var err error | ||
if r.ContentLength != 0 { | ||
var quota = struct { | ||
|
@@ -55,9 +56,9 @@ func handlePost(w http.ResponseWriter, r *http.Request, tokenLifetimeInHours int | |
http.Error(w, fmt.Sprintf("invalid Unit type sent in request body, Valid types are [Gi,Ti,Pi]: %v", quota.Unit), http.StatusBadRequest) | ||
return | ||
} | ||
storageQuotaInGiB = ptr.To(unitAsGiB * quota.Value) | ||
roleSpec.ClientOptions = services.ClientRoleOptions{StorageQuotaInGiB: unitAsGiB * quota.Value} | ||
} | ||
if onboardingToken, err := util.GenerateOnboardingToken(tokenLifetimeInHours, onboardingPrivateKeyFilePath, storageQuotaInGiB); err != nil { | ||
if onboardingToken, err := util.GenerateOnboardingToken(tokenLifetimeInHours, onboardingPrivateKeyFilePath, roleSpec); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that is done, the ticket will be generated for an empty role if the body is empty, which will always lead to failure while onboarding since we cannot verify the role |
||
klog.Errorf("failed to get onboardig token: %v", err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Header().Set("Content-Type", handlers.ContentTypeTextPlain) | ||
|
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.
isn't this repeating the default case of below switch?
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.
Yes, I am expecting this function to be called while onboarding (onboarding clients and onboarding peers). This check is required so that we don't enter the peer role ticket while onboarding the client and vice-versa.
I could remove the default case in the switch as the code would never reach it.