Skip to content

Commit 08ea069

Browse files
change doc URL if UI is running in k8s (#2484)
Co-authored-by: Prakash Senthil Vel <23444145+prakashsvmx@users.noreply.github.com>
1 parent e7a41b4 commit 08ea069

File tree

10 files changed

+55
-7
lines changed

10 files changed

+55
-7
lines changed

models/login_details.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operatorapi/embedded_spec.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operatorapi/login.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
xoauth2 "golang.org/x/oauth2"
2626

2727
"github.com/minio/minio-go/v7/pkg/credentials"
28+
"github.com/minio/pkg/env"
2829

2930
"github.com/minio/console/restapi"
3031

@@ -93,6 +94,15 @@ func login(credentials restapi.ConsoleCredentialsI) (*string, error) {
9394
return &token, nil
9495
}
9596

97+
// isKubernetes returns true if minio is running in kubernetes.
98+
func isKubernetes() bool {
99+
// Kubernetes env used to validate if we are
100+
// indeed running inside a kubernetes pod
101+
// is KUBERNETES_SERVICE_HOST
102+
// https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/kubelet_pods.go#L541
103+
return env.Get("KUBERNETES_SERVICE_HOST", "") != ""
104+
}
105+
96106
// getLoginDetailsResponse returns information regarding the Console authentication mechanism.
97107
func getLoginDetailsResponse(params authApi.LoginDetailParams) (*models.LoginDetails, *models.Error) {
98108
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
@@ -129,6 +139,7 @@ func getLoginDetailsResponse(params authApi.LoginDetailParams) (*models.LoginDet
129139
LoginStrategy: loginStrategy,
130140
RedirectRules: redirectRules,
131141
IsDirectPV: getDirectPVEnabled(),
142+
IsK8S: isKubernetes(),
132143
}
133144
return loginDetails, nil
134145
}

portal-ui/src/screens/LoginPage/LoginPage.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ const Login = () => {
291291
);
292292
const navigateTo = useSelector((state: AppState) => state.login.navigateTo);
293293

294-
const directPVMode = useSelector((state: AppState) => state.login.isDirectPV);
294+
const isDirectPV = useSelector((state: AppState) => state.login.isDirectPV);
295+
const isK8S = useSelector((state: AppState) => state.login.isK8S);
295296

296297
const isOperator =
297298
loginStrategy.loginStrategy === loginStrategyType.serviceAccount ||
@@ -479,12 +480,18 @@ const Login = () => {
479480
let modeLogo: "console" | "directpv" | "operator" | "kes" | "subnet" =
480481
"console";
481482

482-
if (directPVMode) {
483+
if (isDirectPV) {
483484
modeLogo = "directpv";
484485
} else if (isOperator) {
485486
modeLogo = "operator";
486487
}
487488

489+
let docsURL = "https://min.io/docs/minio/linux/index.html?ref=con";
490+
if (isK8S) {
491+
docsURL =
492+
"https://min.io/docs/minio/kubernetes/upstream/index.html?ref=con";
493+
}
494+
488495
return (
489496
<Fragment>
490497
<MainError />
@@ -493,11 +500,7 @@ const Login = () => {
493500
form={loginComponent}
494501
formFooter={
495502
<Fragment>
496-
<a
497-
href="https://min.io/docs/minio/linux/index.html?ref=con"
498-
target="_blank"
499-
rel="noreferrer"
500-
>
503+
<a href={docsURL} target="_blank" rel="noreferrer">
501504
Documentation
502505
</a>
503506
<span className={classes.separator}>|</span>

portal-ui/src/screens/LoginPage/loginSlice.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface LoginState {
3838
latestMinIOVersion: string;
3939
loadingVersion: boolean;
4040
isDirectPV: boolean;
41+
isK8S: boolean;
4142

4243
navigateTo: string;
4344
}
@@ -57,6 +58,7 @@ const initialState: LoginState = {
5758
latestMinIOVersion: "",
5859
loadingVersion: true,
5960
isDirectPV: false,
61+
isK8S: false,
6062

6163
navigateTo: "",
6264
};
@@ -110,6 +112,7 @@ export const loginSlice = createSlice({
110112
if (action.payload) {
111113
state.loginStrategy = action.payload;
112114
state.isDirectPV = !!action.payload.isDirectPV;
115+
state.isK8S = !!action.payload.isK8S;
113116
}
114117
})
115118
.addCase(doLoginAsync.pending, (state, action) => {

portal-ui/src/screens/LoginPage/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface ILoginDetails {
1818
loginStrategy: loginStrategyType;
1919
redirectRules: redirectRule[];
2020
isDirectPV?: boolean;
21+
isK8S?: boolean;
2122
}
2223

2324
export interface redirectRule {

restapi/embedded_spec.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

restapi/user_login.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
authApi "github.com/minio/console/restapi/operations/auth"
3232
"github.com/minio/madmin-go/v2"
3333
"github.com/minio/minio-go/v7/pkg/credentials"
34+
"github.com/minio/pkg/env"
3435
)
3536

3637
func registerLoginHandlers(api *operations.ConsoleAPI) {
@@ -153,6 +154,15 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *model
153154
return loginResponse, nil
154155
}
155156

157+
// isKubernetes returns true if minio is running in kubernetes.
158+
func isKubernetes() bool {
159+
// Kubernetes env used to validate if we are
160+
// indeed running inside a kubernetes pod
161+
// is KUBERNETES_SERVICE_HOST
162+
// https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/kubelet_pods.go#L541
163+
return env.Get("KUBERNETES_SERVICE_HOST", "") != ""
164+
}
165+
156166
// getLoginDetailsResponse returns information regarding the Console authentication mechanism.
157167
func getLoginDetailsResponse(params authApi.LoginDetailParams, openIDProviders oauth2.OpenIDPCfg) (*models.LoginDetails, *models.Error) {
158168
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
@@ -193,6 +203,7 @@ func getLoginDetailsResponse(params authApi.LoginDetailParams, openIDProviders o
193203
loginDetails = &models.LoginDetails{
194204
LoginStrategy: loginStrategy,
195205
RedirectRules: redirectRules,
206+
IsK8S: isKubernetes(),
196207
}
197208
return loginDetails, nil
198209
}

swagger-console.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4057,6 +4057,8 @@ definitions:
40574057
$ref: "#/definitions/redirectRule"
40584058
isDirectPV:
40594059
type: boolean
4060+
isK8S:
4061+
type: boolean
40604062
loginOauth2AuthRequest:
40614063
type: object
40624064
required:

swagger-operator.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,8 @@ definitions:
16451645
$ref: "#/definitions/redirectRule"
16461646
isDirectPV:
16471647
type: boolean
1648+
isK8S:
1649+
type: boolean
16481650
loginRequest:
16491651
type: object
16501652
properties:

0 commit comments

Comments
 (0)