Skip to content

Commit cabf8b8

Browse files
committed
Use docker to build cassandra jar file
1 parent 2845293 commit cabf8b8

File tree

10 files changed

+325
-266
lines changed

10 files changed

+325
-266
lines changed

cassandra/image/Makefile cassandra/Makefile

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,29 @@
1313
# limitations under the License.
1414

1515
# build the cassandra image.
16-
VERSION=v13
16+
VERSION=v14
1717
PROJECT_ID?=google_samples
1818
PROJECT=gcr.io/${PROJECT_ID}
1919
CASSANDRA_VERSION=3.11.2
2020

2121
all: kubernetes-cassandra.jar build
2222

23-
kubernetes-cassandra.jar: ../java/* ../java/src/main/java/io/k8s/cassandra/*.java
24-
cd ../java && mvn clean && mvn package
25-
mv ../java/target/kubernetes-cassandra*.jar files/kubernetes-cassandra.jar
26-
cd ../java && mvn clean
23+
build-go:
24+
go build -a -installsuffix cgo \
25+
-ldflags "-s -w" \
26+
-o image/files/cassandra-seed.so -buildmode=c-shared go/main.go
27+
28+
kubernetes-cassandra.jar:
29+
@echo "Building kubernetes-cassandra.jar"
30+
docker run -v ${PWD}/java:/usr/src/app maven:3-jdk-8-onbuild-alpine mvn clean install
31+
cp java/target/kubernetes-cassandra*.jar image/files/kubernetes-cassandra.jar
2732

2833
container:
2934
@echo "Building ${PROJECT}/cassandra:${VERSION}"
30-
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" -t ${PROJECT}/cassandra:${VERSION} .
35+
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" -t ${PROJECT}/cassandra:${VERSION} image
3136

3237
container-dev:
33-
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" --build-arg "DEV_CONTAINER=true" -t ${PROJECT}/cassandra:${VERSION}-dev .
38+
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" --build-arg "DEV_CONTAINER=true" -t ${PROJECT}/cassandra:${VERSION}-dev image
3439

3540
build: container container-dev
3641

cassandra/cassandra-statefulset.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
terminationGracePeriodSeconds: 1800
1919
containers:
2020
- name: cassandra
21-
image: gcr.io/google-samples/cassandra:v13
21+
image: gcr.io/google-samples/cassandra:v14
2222
imagePullPolicy: Always
2323
ports:
2424
- containerPort: 7000
@@ -60,6 +60,8 @@ spec:
6060
value: "DC1-K8Demo"
6161
- name: CASSANDRA_RACK
6262
value: "Rack1-K8Demo"
63+
- name: CASSANDRA_SEED_PROVIDER
64+
value: io.k8s.cassandra.KubernetesSeedProvider
6365
- name: POD_IP
6466
valueFrom:
6567
fieldRef:

cassandra/go/main.go

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package main
2+
3+
// #include <stdio.h>
4+
// #include <stdlib.h>
5+
import "C"
6+
7+
import (
8+
"context"
9+
"encoding/json"
10+
"log"
11+
"strings"
12+
"unicode"
13+
"unsafe"
14+
15+
"github.com/ericchiang/k8s"
16+
corev1 "github.com/ericchiang/k8s/apis/core/v1"
17+
)
18+
19+
type endpoints struct {
20+
IPs []string `json:"ips"`
21+
}
22+
23+
// GetEndpoints searches the endpoints of a service returning a list of IP addresses.
24+
//export GetEndpoints
25+
func GetEndpoints(namespace, service, defSeeds *C.char) *C.char {
26+
ns := C.GoString(namespace)
27+
svc := C.GoString(service)
28+
seeds := C.GoString(defSeeds)
29+
30+
s := strings.Map(func(r rune) rune {
31+
if unicode.IsSpace(r) {
32+
return -1
33+
}
34+
return r
35+
}, seeds)
36+
37+
nseeds := strings.Split(s, ",")
38+
client, err := k8s.NewInClusterClient()
39+
if err != nil {
40+
log.Printf("unexpected error opening a connection against API server: %v\n", err)
41+
log.Printf("returning default seeds: %v\n", nseeds)
42+
return buildEndpoints(nseeds)
43+
}
44+
45+
ips := make([]string, 0)
46+
47+
var endpoints corev1.Endpoints
48+
err = client.Get(context.Background(), ns, svc, &endpoints)
49+
if err != nil {
50+
log.Printf("unexpected error obtaining information about service endpoints: %v\n", err)
51+
log.Printf("returning default seeds: %v\n", nseeds)
52+
return buildEndpoints(nseeds)
53+
}
54+
55+
for _, endpoint := range endpoints.Subsets {
56+
for _, address := range endpoint.Addresses {
57+
ips = append(ips, *address.Ip)
58+
}
59+
}
60+
61+
if len(ips) == 0 {
62+
return buildEndpoints(nseeds)
63+
}
64+
65+
return buildEndpoints(ips)
66+
}
67+
68+
func buildEndpoints(ips []string) *C.char {
69+
b, err := json.Marshal(&endpoints{ips})
70+
if err != nil {
71+
log.Printf("unexpected error serializing JSON response: %v\n", err)
72+
rc := C.CString(`{"ips":[]}`)
73+
defer C.free(unsafe.Pointer(rc))
74+
return rc
75+
}
76+
77+
rc := C.CString(string(b))
78+
defer C.free(unsafe.Pointer(rc))
79+
return rc
80+
}
81+
82+
func main() {}

cassandra/image/files/build.sh

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ else
5555
rm -rf $CASSANDRA_HOME/pylib;
5656
fi
5757

58+
mv /kubernetes-cassandra.jar /usr/local/apache-cassandra-${CASSANDRA_VERSION}/lib
59+
mv /cassandra-seed.so /etc/cassandra/
60+
mv /cassandra-seed.h /usr/local/lib/include
61+
5862
apt-get -y purge localepurge
5963
apt-get -y autoremove
6064
apt-get clean
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Created by "go tool cgo" - DO NOT EDIT. */
2+
3+
/* package command-line-arguments */
4+
5+
6+
#line 1 "cgo-builtin-prolog"
7+
8+
#include <stddef.h> /* for ptrdiff_t below */
9+
10+
#ifndef GO_CGO_EXPORT_PROLOGUE_H
11+
#define GO_CGO_EXPORT_PROLOGUE_H
12+
13+
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
14+
15+
#endif
16+
17+
/* Start of preamble from import "C" comments. */
18+
19+
20+
#line 3 "/home/aledbf/go/src/k8s.io/examples/cassandra/go/main.go"
21+
#include <stdio.h>
22+
#include <stdlib.h>
23+
24+
#line 1 "cgo-generated-wrapper"
25+
26+
27+
/* End of preamble from import "C" comments. */
28+
29+
30+
/* Start of boilerplate cgo prologue. */
31+
#line 1 "cgo-gcc-export-header-prolog"
32+
33+
#ifndef GO_CGO_PROLOGUE_H
34+
#define GO_CGO_PROLOGUE_H
35+
36+
typedef signed char GoInt8;
37+
typedef unsigned char GoUint8;
38+
typedef short GoInt16;
39+
typedef unsigned short GoUint16;
40+
typedef int GoInt32;
41+
typedef unsigned int GoUint32;
42+
typedef long long GoInt64;
43+
typedef unsigned long long GoUint64;
44+
typedef GoInt64 GoInt;
45+
typedef GoUint64 GoUint;
46+
typedef __SIZE_TYPE__ GoUintptr;
47+
typedef float GoFloat32;
48+
typedef double GoFloat64;
49+
typedef float _Complex GoComplex64;
50+
typedef double _Complex GoComplex128;
51+
52+
/*
53+
static assertion to make sure the file is being used on architecture
54+
at least with matching size of GoInt.
55+
*/
56+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
57+
58+
typedef _GoString_ GoString;
59+
typedef void *GoMap;
60+
typedef void *GoChan;
61+
typedef struct { void *t; void *v; } GoInterface;
62+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
63+
64+
#endif
65+
66+
/* End of boilerplate cgo prologue. */
67+
68+
#ifdef __cplusplus
69+
extern "C" {
70+
#endif
71+
72+
73+
// GetEndpoints searches the endpoints of a service returning a list of IP addresses.
74+
75+
extern char* GetEndpoints(char* p0, char* p1, char* p2);
76+
77+
#ifdef __cplusplus
78+
}
79+
#endif
-1.91 KB
Binary file not shown.

cassandra/java/pom.xml

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
<modelVersion>4.0.0</modelVersion>
1818
<groupId>io.k8s.cassandra</groupId>
1919
<artifactId>kubernetes-cassandra</artifactId>
20-
<version>1.0.2</version>
20+
<version>1.0.3</version>
2121
<build>
2222
<plugins>
2323
<plugin>
2424
<artifactId>maven-compiler-plugin</artifactId>
25-
<version>3.5.1</version>
25+
<version>3.5.1</version>
2626
<configuration>
2727
<source>1.8</source>
2828
<target>1.8</target>
@@ -33,7 +33,7 @@
3333

3434
<properties>
3535
<logback.version>1.1.3</logback.version>
36-
<cassandra.version>3.9</cassandra.version>
36+
<cassandra.version>3.11.2</cassandra.version>
3737
</properties>
3838

3939
<dependencies>
@@ -61,7 +61,6 @@
6161
<version>${logback.version}</version>
6262
<scope>provided</scope>
6363
</dependency>
64-
6564
<dependency>
6665
<groupId>ch.qos.logback</groupId>
6766
<artifactId>logback-core</artifactId>
@@ -72,14 +71,13 @@
7271
<dependency>
7372
<groupId>org.codehaus.jackson</groupId>
7473
<artifactId>jackson-core-asl</artifactId>
75-
<version>1.6.3</version>
74+
<version>1.9.13</version>
7675
<scope>provided</scope>
7776
</dependency>
78-
7977
<dependency>
8078
<groupId>org.codehaus.jackson</groupId>
8179
<artifactId>jackson-mapper-asl</artifactId>
82-
<version>1.6.3</version>
80+
<version>1.9.13</version>
8381
<scope>provided</scope>
8482
</dependency>
8583

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
/*
3+
* Copyright (C) 2018 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
18+
package io.k8s.cassandra;
19+
20+
import java.util.Arrays;
21+
import java.util.List;
22+
23+
import com.sun.jna.Library;
24+
import com.sun.jna.Pointer;
25+
import com.sun.jna.Structure;
26+
27+
public interface GoInterface extends Library {
28+
public String GetEndpoints(String namespace, String service, String seeds);
29+
30+
public class GoSlice extends Structure {
31+
public static class ByValue extends GoSlice implements Structure.ByValue {
32+
}
33+
34+
public Pointer data;
35+
public long len;
36+
public long cap;
37+
38+
protected List<String> getFieldOrder() {
39+
return Arrays.asList(new String[] { "data", "len", "cap" });
40+
}
41+
}
42+
43+
public class GoString extends Structure {
44+
public static class ByValue extends GoString implements Structure.ByValue {
45+
}
46+
47+
public String p;
48+
public long n;
49+
50+
protected List<String> getFieldOrder() {
51+
return Arrays.asList(new String[] { "p", "n" });
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)