@@ -1071,6 +1071,9 @@ describe('KubernetesObject', () => {
10711071 kc . loadFromOptions ( testConfigOptions ) ;
10721072 client = KubernetesObjectApi . makeApiClient ( kc ) ;
10731073 ( client as any ) . apiVersionResourceCache . v1 = JSON . parse ( resourceBodies . core ) ;
1074+ ( client as any ) . apiVersionResourceCache [ 'networking.k8s.io/v1' ] = JSON . parse (
1075+ resourceBodies . networking ,
1076+ ) ;
10741077 } ) ;
10751078
10761079 it ( 'should modify resources with defaults' , async ( ) => {
@@ -1520,6 +1523,125 @@ describe('KubernetesObject', () => {
15201523 }
15211524 } ) ;
15221525
1526+ it ( 'should properly serialize resources on modify' , async ( ) => {
1527+ const netPol = {
1528+ apiVersion : 'networking.k8s.io/v1' ,
1529+ kind : 'NetworkPolicy' ,
1530+ metadata : {
1531+ name : 'k8s-js-client-test' ,
1532+ namespace : 'default' ,
1533+ } ,
1534+ spec : {
1535+ podSelector : {
1536+ matchLabels : {
1537+ app : 'my-app' ,
1538+ } ,
1539+ } ,
1540+ policyTypes : [ 'Ingress' ] ,
1541+ ingress : [
1542+ {
1543+ _from : [
1544+ {
1545+ podSelector : { matchLabels : { app : 'foo' } } ,
1546+ } ,
1547+ ] ,
1548+ ports : [ { port : 123 } ] ,
1549+ } ,
1550+ ] ,
1551+ } ,
1552+ } ;
1553+ const serializedNetPol = {
1554+ apiVersion : 'networking.k8s.io/v1' ,
1555+ kind : 'NetworkPolicy' ,
1556+ metadata : {
1557+ name : 'k8s-js-client-test' ,
1558+ namespace : 'default' ,
1559+ } ,
1560+ spec : {
1561+ podSelector : {
1562+ matchLabels : {
1563+ app : 'my-app' ,
1564+ } ,
1565+ } ,
1566+ policyTypes : [ 'Ingress' ] ,
1567+ ingress : [
1568+ {
1569+ from : [
1570+ {
1571+ podSelector : { matchLabels : { app : 'foo' } } ,
1572+ } ,
1573+ ] ,
1574+ ports : [ { port : 123 } ] ,
1575+ } ,
1576+ ] ,
1577+ } ,
1578+ } ;
1579+ const returnBody = `{
1580+ "kind": "NetworkPolicy",
1581+ "apiVersion": "networking.k8s.io/v1",
1582+ "metadata": {
1583+ "name": "k8s-js-client-test",
1584+ "namespace": "default",
1585+ "selfLink": "/api/v1/namespaces/default/services/k8s-js-client-test",
1586+ "uid": "6a43eddc-26bf-424e-ab30-cde3041a706a",
1587+ "resourceVersion": "32373",
1588+ "creationTimestamp": "2020-05-11T17:34:25Z"
1589+ },
1590+ "spec": {
1591+ "policyTypes": ["Ingress"],
1592+ "podSelector": {
1593+ "matchLabels": {
1594+ "app": "my-app"
1595+ }
1596+ },
1597+ "ingress": [
1598+ {
1599+ "from": [{
1600+ "podSelector": {
1601+ "matchLabels": {
1602+ "app": "foo"
1603+ }
1604+ }
1605+ }],
1606+ "ports": [{"port": 123}]
1607+ }
1608+ ]
1609+ }
1610+ }` ;
1611+ const methods = [
1612+ {
1613+ m : client . create ,
1614+ v : 'POST' ,
1615+ p : '/apis/networking.k8s.io/v1/namespaces/default/networkpolicies' ,
1616+ c : 201 ,
1617+ b : returnBody ,
1618+ } ,
1619+ {
1620+ m : client . replace ,
1621+ v : 'PUT' ,
1622+ p : '/apis/networking.k8s.io/v1/namespaces/default/networkpolicies/k8s-js-client-test' ,
1623+ c : 200 ,
1624+ b : returnBody ,
1625+ } ,
1626+ {
1627+ m : client . patch ,
1628+ v : 'PATCH' ,
1629+ p : '/apis/networking.k8s.io/v1/namespaces/default/networkpolicies/k8s-js-client-test' ,
1630+ c : 200 ,
1631+ b : returnBody ,
1632+ } ,
1633+ ] ;
1634+ for ( const m of methods ) {
1635+ const scope = nock ( 'https://d.i.y' )
1636+ . intercept ( m . p , m . v , serializedNetPol )
1637+ . reply ( m . c , m . b , contentTypeJsonHeader ) ;
1638+ // TODO: Figure out why Typescript barfs if we do m.call
1639+ const hack_m = m . m as any ;
1640+ await hack_m . call ( client , netPol ) ;
1641+ scope . done ( ) ;
1642+ }
1643+ } ) ;
1644+
15231645 it ( 'should replace a resource' , async ( ) => {
15241646 const s = {
15251647 apiVersion : 'v1' ,
0 commit comments