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

Finish namespace support feature #3496

Merged
merged 3 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
592 changes: 83 additions & 509 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"zone.js": "0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.12.0",
"@angular-devkit/build-angular": "0.12.1",
"@angular/cli": "7.2.0",
"@angular/compiler-cli": "7.1.4",
"@angular/language-service": "7.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/auth/api/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ToAuthenticationModes(modes []string) AuthenticationModes {
// List of protected resources that should be filtered out from dashboard UI.
var protectedResources = []ProtectedResource{
{EncryptionKeyHolderName, args.Holder.GetNamespace()},
{CertificateHolderSecretName, CertificateHolderSecretNamespace},
{CertificateHolderSecretName, args.Holder.GetNamespace()},
}

// ShouldRejectRequest returns true if url contains name and namespace of resource that should be filtered out from
Expand Down
1 change: 0 additions & 1 deletion src/app/backend/auth/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const (

// Resource information that are used as certificate storage for custom certificates used by the user.
CertificateHolderSecretName = "kubernetes-dashboard-certs"
CertificateHolderSecretNamespace = "kube-system"

// Expiration time (in seconds) of tokens generated by dashboard. Default: 15 min.
DefaultTokenTTL = 900
Expand Down
1 change: 0 additions & 1 deletion src/app/backend/auth/jwe/keyholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type rsaKeyHolder struct {
key *rsa.PrivateKey
synchronizer syncApi.Synchronizer
mux sync.Mutex
namespace string
}

// Encrypter implements key holder interface. See KeyHolder for more information.
Expand Down
4 changes: 0 additions & 4 deletions src/app/backend/auth/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func (self *fakeClientManager) CSRFKey() string {
return ""
}

func (self *fakeClientManager) GetNamespace() string {
return ""
}

func (self *fakeClientManager) HasAccess(authInfo api.AuthInfo) error {
return self.HasAccessError
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/backend/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
"os"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/pflag"

"github.com/kubernetes/dashboard/src/app/backend/args"
"github.com/kubernetes/dashboard/src/app/backend/auth"
authApi "github.com/kubernetes/dashboard/src/app/backend/auth/api"
Expand All @@ -39,8 +42,6 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/settings"
"github.com/kubernetes/dashboard/src/app/backend/sync"
"github.com/kubernetes/dashboard/src/app/backend/systembanner"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/pflag"
)

var (
Expand Down Expand Up @@ -71,8 +72,7 @@ var (
argSystemBannerSeverity = pflag.String("system-banner-severity", "INFO", "Severity of system banner. Should be one of 'INFO|WARNING|ERROR'. Default: 'INFO'.")
argAPILogLevel = pflag.String("api-log-level", "INFO", "Level of API request logging. Should be one of 'INFO|NONE|DEBUG'. Default: 'INFO'.")
argDisableSettingsAuthorizer = pflag.Bool("disable-settings-authorizer", false, "When enabled, Dashboard settings page will not require user to be logged in and authorized to access settings page.")
defNamespace = getEnv("POD_NAMESPACE", "kube-system")
argNamespace = pflag.String("namespace", defNamespace, "When non-default namespace is used, create encryption key in the specified namespace. Default: 'kube-system'.")
argNamespace = pflag.String("namespace", getEnv("POD_NAMESPACE", "kube-system"), "When non-default namespace is used, create encryption key in the specified namespace. Default: 'kube-system'.")
)

func main() {
Expand Down Expand Up @@ -108,7 +108,7 @@ func main() {
authManager := initAuthManager(clientManager)

// Init settings manager
settingsManager := settings.NewSettingsManager(clientManager, args.Holder.GetNamespace())
settingsManager := settings.NewSettingsManager(clientManager)

// Init system banner manager
systemBannerManager := systembanner.NewSystemBannerManager(args.Holder.GetSystemBanner(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/handler/apihandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func getTokenManager() authApi.TokenManager {
func TestCreateHTTPAPIHandler(t *testing.T) {
cManager := client.NewClientManager("", "http://localhost:8080")
authManager := auth.NewAuthManager(cManager, getTokenManager(), authApi.AuthenticationModes{}, true)
sManager := settings.NewSettingsManager(cManager, "")
sManager := settings.NewSettingsManager(cManager)
sbManager := systembanner.NewSystemBannerManager("Hello world!", "INFO")
_, err := CreateHTTPAPIHandler(nil, cManager, authManager, sManager, sbManager)
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions src/app/backend/settings/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ const (
// SettingsConfigMapName contains a name of config map, that stores settings.
SettingsConfigMapName = "kubernetes-dashboard-settings"

// SettingsConfigMapNamespace contains a namespace of config map, that stores settings.
SettingsConfigMapNamespace = "kube-system"

// ConfigMapKindName is a name of config map kind.
ConfigMapKindName = "ConfigMap"

Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/settings/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (self *SettingsHandler) handleSettingsGlobalCanI(request *restful.Request,
}

canI := self.manager.clientManager.CanI(request, clientapi.ToSelfSubjectAccessReview(
self.manager.namespace,
args.Holder.GetNamespace(),
api.SettingsConfigMapName,
api.ConfigMapKindName,
verb,
Expand Down
2 changes: 1 addition & 1 deletion src/app/backend/settings/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestIntegrationHandler_Install(t *testing.T) {
iHandler := NewSettingsHandler(NewSettingsManager(nil, ""))
iHandler := NewSettingsHandler(NewSettingsManager(nil))
ws := new(restful.WebService)
iHandler.Install(ws)

Expand Down
16 changes: 6 additions & 10 deletions src/app/backend/settings/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"log"
"reflect"

"github.com/kubernetes/dashboard/src/app/backend/args"
clientapi "github.com/kubernetes/dashboard/src/app/backend/client/api"
"github.com/kubernetes/dashboard/src/app/backend/settings/api"
v1 "k8s.io/api/core/v1"
Expand All @@ -31,24 +32,19 @@ type SettingsManager struct {
settings map[string]api.Settings
rawSettings map[string]string
clientManager clientapi.ClientManager
namespace string
}

// NewSettingsManager creates new settings manager.
func NewSettingsManager(clientManager clientapi.ClientManager, namespace string) SettingsManager {
if namespace == "" {
namespace = api.SettingsConfigMapNamespace
}
func NewSettingsManager(clientManager clientapi.ClientManager) SettingsManager {
return SettingsManager{
settings: make(map[string]api.Settings),
clientManager: clientManager,
namespace: namespace,
}
}

// load config map data into settings manager and return true if new settings are different.
func (sm *SettingsManager) load(client kubernetes.Interface) (configMap *v1.ConfigMap, isDifferent bool) {
configMap, err := client.CoreV1().ConfigMaps(sm.namespace).
configMap, err := client.CoreV1().ConfigMaps(args.Holder.GetNamespace()).
Get(api.SettingsConfigMapName, metav1.GetOptions{})
if err != nil {
log.Printf("Cannot find settings config map: %s", err.Error())
Expand Down Expand Up @@ -77,8 +73,8 @@ func (sm *SettingsManager) load(client kubernetes.Interface) (configMap *v1.Conf

// restoreConfigMap restores settings config map using default global settings.
func (sm *SettingsManager) restoreConfigMap(client kubernetes.Interface) {
restoredConfigMap, err := client.CoreV1().ConfigMaps(sm.namespace).
Create(api.GetDefaultSettingsConfigMap(sm.namespace))
restoredConfigMap, err := client.CoreV1().ConfigMaps(args.Holder.GetNamespace()).
Create(api.GetDefaultSettingsConfigMap(args.Holder.GetNamespace()))
if err != nil {
log.Printf("Cannot restore settings config map: %s", err.Error())
} else {
Expand Down Expand Up @@ -116,6 +112,6 @@ func (sm *SettingsManager) SaveGlobalSettings(client kubernetes.Interface, s *ap
}

cm.Data[api.GlobalSettingsKey] = s.Marshal()
_, err := client.CoreV1().ConfigMaps(sm.namespace).Update(cm)
_, err := client.CoreV1().ConfigMaps(args.Holder.GetNamespace()).Update(cm)
return err
}
27 changes: 7 additions & 20 deletions src/app/backend/settings/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,16 @@ import (
)

func TestNewSettingsManager(t *testing.T) {
sm := NewSettingsManager(nil)

cases := []struct {
namespace, expectedNamespace string
}{
{"testns", "testns"},
{"", "kube-system"},
}
for _, c := range cases {
sm := NewSettingsManager(nil, c.namespace)

if len(sm.settings) > 0 {
t.Error("new settings manager should have no settings set")
}

if sm.namespace != c.expectedNamespace {
t.Fatalf("Expected namespace to be '%s' got '%s'.", c.expectedNamespace, sm.namespace)
}
if len(sm.settings) > 0 {
t.Error("new settings manager should have no settings set")
}
}

func TestSettingsManager_GetGlobalSettings(t *testing.T) {
sm := NewSettingsManager(nil, "")
client := fake.NewSimpleClientset(api.GetDefaultSettingsConfigMap(sm.namespace))
sm := NewSettingsManager(nil)
client := fake.NewSimpleClientset(api.GetDefaultSettingsConfigMap(""))
gs := sm.GetGlobalSettings(client)

if !reflect.DeepEqual(api.GetDefaultSettings(), gs) {
Expand All @@ -54,8 +41,8 @@ func TestSettingsManager_GetGlobalSettings(t *testing.T) {
}

func TestSettingsManager_SaveGlobalSettings(t *testing.T) {
sm := NewSettingsManager(nil, "")
client := fake.NewSimpleClientset(api.GetDefaultSettingsConfigMap(sm.namespace))
sm := NewSettingsManager(nil)
client := fake.NewSimpleClientset(api.GetDefaultSettingsConfigMap(""))
defaults := api.GetDefaultSettings()
err := sm.SaveGlobalSettings(client, &defaults)

Expand Down
3 changes: 1 addition & 2 deletions src/app/frontend/common/services/global/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import 'rxjs/add/operator/switchMap';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {onLogin} from '@api/frontendapi';
import {StateService, TransitionService} from '@uirouter/angular';
import {TargetState, Transition} from '@uirouter/core';
import {StateService, TargetState, Transition, TransitionService} from '@uirouter/core';
import {CookieService} from 'ngx-cookie-service';
import {Observable} from 'rxjs/Observable';
import {AuthResponse, CsrfToken, K8sError, LoginSpec, LoginStatus} from 'typings/backendapi';
Expand Down
3 changes: 1 addition & 2 deletions src/app/frontend/index.router.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {UIRouter} from '@uirouter/angular';
import {HookMatchCriteria, HookMatchCriterion} from '@uirouter/core';
import {HookMatchCriteria, HookMatchCriterion, UIRouter} from '@uirouter/core/lib';

import {NAMESPACE_STATE_PARAM} from './common/params/params';
import {AuthService} from './common/services/global/authentication';
Expand Down