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

Add ability to import K8S endpoints from kube config file #381

Merged
merged 35 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9c5a06f
Merge remote-tracking branch 'origin/master' into kc-import
nwmac Mar 1, 2020
60ff35d
Merge remote-tracking branch 'origin/master' into kc-import
nwmac Apr 24, 2020
6029cba
Fix table passing issue
nwmac Apr 24, 2020
c443c19
WIP: Import from kube config file
nwmac May 27, 2020
9e92ea3
Merge remote-tracking branch 'origin/master' into kc-import
nwmac May 27, 2020
a8d399d
Minor tidy ups
nwmac May 27, 2020
95f894c
Remove debugging code
nwmac May 27, 2020
ca91e93
Merge branch 'kc-import' of github.com:SUSE/stratos into kc-import
nwmac May 27, 2020
2f56d22
Fix for error message being swallowed
nwmac May 27, 2020
a1b1a75
Improvements to load, add edit name
richard-cox Jun 2, 2020
1470ca1
Specific fixes for upstream
richard-cox Jun 2, 2020
738dc2b
Rename name column component, fix default context selection when invalid
richard-cox Jun 3, 2020
20293cf
Tidying up, add skip ssl, fix register of new
richard-cox Jun 3, 2020
4905a04
Allow user to skip connect by not suppling user
richard-cox Jun 4, 2020
e40ff91
Tidying up, set AZK type, fixes
richard-cox Jun 5, 2020
cc1af03
Minor fixes, subtle edit symbols
richard-cox Jun 5, 2020
fb8956c
Fix case where cluster is register only but cannot connect, allow use…
richard-cox Jun 5, 2020
953484f
Add detection for EKS
richard-cox Jun 5, 2020
10e0497
Remove border between row that's errored and it's errror description row
richard-cox Jun 5, 2020
e0b740e
Fix unit tests
richard-cox Jun 5, 2020
ac0afe4
Set initial state of skip ssl checkbox given request to kube
richard-cox Jun 8, 2020
bfee9ec
Fix unit tests
richard-cox Jun 8, 2020
707b18e
Remove some console.logs
richard-cox Jun 8, 2020
db8d9ae
Multiple small changes/fixes
richard-cox Jun 8, 2020
91be251
Fix connect error status message, change title of register endpoint s…
richard-cox Jun 8, 2020
85c38b7
Improve table row error
richard-cox Jun 8, 2020
21f13f2
Spacing
richard-cox Jun 8, 2020
1ddc84a
Changes following review
richard-cox Jun 9, 2020
2811d7a
Changes following review
richard-cox Jun 9, 2020
e76f634
Fix build warning which is silent in dev world
richard-cox Jun 9, 2020
d1ff8fc
Merge remote-tracking branch 'origin/master' into kc-import
richard-cox Jun 11, 2020
cdc39bb
Fixes following merge
richard-cox Jun 11, 2020
ec83bdd
Fix e2e test
richard-cox Jun 12, 2020
308e2d5
Merge remote-tracking branch 'origin/master' into kc-import
richard-cox Jun 23, 2020
8ece34e
Add icon for kube config import
nwmac Jun 25, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { ComponentFactoryResolver, Injector } from '@angular/core';
import { FormBuilder } from '@angular/forms';

import { entityCatalog } from '../../../../../store/src/entity-catalog/entity-catalog';
import { ConnectEndpointData } from '../../../features/endpoints/connect.service';
import { RowState } from '../../../shared/components/list/data-sources-controllers/list-data-source-types';
import { KUBERNETES_ENDPOINT_TYPE } from '../kubernetes-entity-factory';
import { EndpointAuthTypeConfig, IAuthForm } from './../../../core/extension/extension-types';
import { KubeConfigFileCluster, KubeConfigFileUser } from './kube-config.types';

/**
* Auth helper tries to figure out the Kubernetes sub-type and auth to use
* based on the kube config file contents
*/
export class KubeConfigAuthHelper {

authTypes: { [name: string]: EndpointAuthTypeConfig } = {};

public subTypes = [];

constructor() {
const epTypeInfo = entityCatalog.getAllEndpointTypes(false);
const k8s = epTypeInfo.find(entity => entity.type === KUBERNETES_ENDPOINT_TYPE);
if (k8s && k8s.definition) {
const defn = k8s.definition;

// Collect all of the auth types
defn.authTypes.forEach(at => {
this.authTypes[at.value] = at;
});

this.subTypes.push({ id: '', name: 'Generic' });

// Collect all of the auth types for the sub-types
defn.subTypes.forEach(st => {
if (st.type !== 'config') {
this.subTypes.push({ id: st.type, name: st.labelShort });
}
st.authTypes.forEach(at => {
this.authTypes[at.value] = at;
});
});

// Sort the subtypes
this.subTypes = this.subTypes.sort((a, b) => a.name.localeCompare(b.name));
}
}

// Try and parse the authentication metadata
public parseAuth(cluster: KubeConfigFileCluster, user: KubeConfigFileUser): RowState {

// Default subtype is generic Kubernetes
cluster._subType = '';

// Certificate authentication first

// In-file certificate authentication
if (user.user['client-certificate-data'] && user.user['client-key-data']) {
// We are good to go - create the form data

// Default is generic kubernetes
let subType = '';
const authType = 'kube-cert-auth';
if (cluster.cluster.server.indexOf('azmk8s.io') >= 0) {
// Probably Azure
subType = 'aks';
cluster._subType = 'aks';
}

const authData = {
authType,
subType,
values: {
cert: user.user['client-certificate-data'],
certKey: user.user['client-key-data']
}
};
user._authData = authData;
return {};
}

if (user.user['client-certificate'] || user.user['client-key']) {
cluster._additionalUserInfo = true;
return {
message: 'This endpoint will be registered but not connected (additional information is required)',
info: true
};
}

const authProvider = user.user['auth-provider'];


if (authProvider && authProvider.config) {
if (authProvider.config['cmd-path'] && authProvider.config['cmd-path'].indexOf('gcloud') !== -1) {
// GKE
cluster._subType = 'gke';
// Can not connect to GKE - user must do so manually
cluster._additionalUserInfo = true;
return {
message: 'This endpoint will be registered but not connected (additional information is required)',
info: true
};
}
}

if (
cluster.cluster.server.indexOf('eks.amazonaws.com') >= 0 ||
(user.user.exec && user.user.exec.command && user.user.exec.command === 'aws-iam-authenticator')
) {
// Probably EKS
cluster._subType = 'eks';
cluster._additionalUserInfo = true;
return {
message: 'This endpoint will be registered but not connected (additional information is required)',
info: true
};
}

return { message: 'Authentication mechanism is not supported', warning: true };
}

// Use the auto component to get the data in the correct format for connecting to the endpoint
public getAuthDataForConnect(resolver: ComponentFactoryResolver, injector: Injector, fb: FormBuilder, user: KubeConfigFileUser)
: ConnectEndpointData | null {

let data = null;

// Get the component to us
if (user && user._authData) {
const authType = this.authTypes[user._authData.authType];

const factory = resolver.resolveComponentFactory<IAuthForm>(authType.component);

const ref = factory.create(injector);

const form = fb.group({
authType: authType.value,
systemShared: false,
authValues: fb.group(user._authData.values)
});

ref.instance.formGroup = form;

// Allow the auth form to supply body content if it needs to
const endpointFormInstance = ref.instance as any;
if (endpointFormInstance.getBody && endpointFormInstance.getValues) {
data = {
authType: authType.value,
authVal: endpointFormInstance.getValues(user._authData.values),
systemShared: false,
bodyContent: endpointFormInstance.getBody()
};
}
ref.destroy();
}
return data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="kubeconfig-import">
<app-table [dataSource]="dataSource" [columns]="columns"></app-table>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:host {
display: flex;
flex: 1;
}

.kubeconfig-import {
flex: 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { KubernetesBaseTestModules } from '../../kubernetes.testing.module';
import { KubeConfigImportComponent } from './kube-config-import.component';

describe('KubeConfigImportComponent', () => {
let component: KubeConfigImportComponent;
let fixture: ComponentFixture<KubeConfigImportComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...KubernetesBaseTestModules
],
declarations: [KubeConfigImportComponent]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(KubeConfigImportComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading